Skip to content
Home Blog Web Development Semantics in Front End Web Development

Semantics in Front End Web Development

  • Web Development
Blueprint Digital
Blueprint Digital

Insights from the Blueprint Digital team.

There are many concepts in front end web development. One that seems to be thrown around everywhere is semantics. In today’s article, I will examine the semantics of front end development and what it means.

So what are semantics?

Personally, I think semantics is hard to define. Merriam-Webster defines semantics as “the study of meanings.” In front end web development, semantics refers to code that corresponds to the information on a web page as opposed to the presentation of it.

An example of bad semantics would be something like this:

<div class="grayBorder">
	<div class="blue">Awesome Blog Post</div>
	<div class="blogpost">Here goes content!</div>
</div>

A better approach would look like this:

<div class="post">
	<h1>Awesome Blog Post</h1>
	<p>Here goes content!</p>
</div>

The top example is considered bad because class names such as blue does not describe what the content is when in fact it is the heading of an article. It may look like a heading on a page, but it is not defined as one, as shown in the bottom example.

If you are using HTML5, then <div class="post"> could be <article>, which would make it even more semantic. As a side note, HTML5 is considered more semantic because of these new tags like <article>, <header>, etc. that actually describe the content that they contain.

Tips for Semantic HTML

The biggest tip for writing semantic HTML is to omit unnecessary markup. Consider this example:

<div class="post">
	<h2>Title</h2>
	...
	...
</div>
<div class="hr"><hr /></div>

Let us assume the <hr> is just a simple line that divides the content. While you could argue that <hr> is not wrong since it is used to define a change in content, the parent <div class="hr"> is largely unnecessary. I would personally argue that the whole line is not needed because .post defines the change in content and the border property on .post would be enough.

Another tip for writing semantic HTML code is to use the tags are they were intended. For example, don’t use a <div> when you really mean <h1>. Also, use <table> for tabular data, not the webpage layout. Remember way back in the day when people used <table> for webpage layout? That is not an acceptable practice anymore.

Tips for Semantic CSS

I think the definition for semantic CSS is even more vague than that of HTML because CSS deals with presentation, not information like HTML. However, there are some tips to make CSS semantic.

Using appropriate names for classes and IDs would make the CSS code more semantic. For example, as shown in the top example, .grayBorder is less semantic than .post because .grayBorder describes the presentation of a <div> element that we want to denote as a blog post. The class name .post is more semantic because it describes the content, which is a blog post.

Similarly, using conventional classes or IDs would be more semantic. For example, the terms “header,” “footer,” and “sidebar” are so common that they have become conventional. That means those terms actually have a meaning associated with them. For example, I would recognize “header” to be the top section of a webpage, and most front end developers would also assume the same. For that reason, using those conventional terms for classes and IDs would be semantic.

Argument Against Semantics

I think web developers should strive to make their code as semantic as possible, but there are exceptions. For example, defining a CSS class and reusing it could be really beneficial. For example, if the website mockup has a certain gradient on elements, using something like .gradient and having all the CSS gradient styles on it would be convenient because classes could be reused and it cuts down on the size of the CSS file. Along the same lines of naming convention, .left and .right would also be acceptable to float elements to left or right.

Another exception is when dealing with cross-browser compatibility. Sometimes, especially with IE, there are times when an extra <div> is necessary.

Conclusion

The ability to work well in a team environment is important for anyone, but I think keeping the code as semantic and clean as possible definitely helps the work flow in a web development team environment. Whether your views on web development semantics is more strict or flexible, I hope you found the article useful.

Ready to Dominate Online and Grow Your Business?

Schedule time to connect with Blueprint about your online goals, or request a free review of marketing campaigns.

Related Posts

Food & Beverage Marketing: How Ingredient Buyers Decide

Food & Beverage Marketing: How Ingredient Buyers Decide

Choosing an ingredient supplier is one of the higher-stakes decisions a food or beverage company makes. It runs through several people over a cycle that can stretch for months, and the deciding factor is usually how much risk each option carries for a business that cannot afford a line stoppage or a recall. For marketing[...]
How to Build a B2B Lead Nurturing Program That Closes Deals

How to Build a B2B Lead Nurturing Program That Closes Deals

Most B2B marketing teams are better at generating leads than keeping them warm. A form gets filled out, the lead lands in the CRM, and nothing happens until a salesperson gets around to it, by which point the buyer has moved on or gone quiet. In a market where the average deal takes months of[...]
How We Took the Grind Out of Link Building Prospecting

How We Took the Grind Out of Link Building Prospecting

Most link building programs stall at the same point, the prospecting spreadsheet. Finding sites worth pitching means pulling competitor backlinks, cross-checking them against what you already know, throwing out the junk, and judging what's left for relevance and quality. It's a few hours of repetitive work before a single outreach email gets written, and when[...]
Previous
Next

Partner with BLUEPRINT to reach your online goals, grow your business and reshape your story.

Get in touch with BLUEPRINT

Reach out to request a discovery call, a free campaign review, or for all other inquiries.

Subscribe to our newsletter