Semantic Markup
Semantic HTML markup means using tags for their intended purpose -- i.e. if you need a heading, here's your <h1> tag and its siblings; need a tabular data representation -- use the <table> tag, and only it.
Sometimes, in the pursuit of eliminating table-based layouts, people go to absurd extremes, and the
<table>tag becomes an outcast, no longer used even for actual tabular data. Don't make this mistake.
Looking slightly ahead, it's worth mentioning HTML5 tags: <article>, <aside>, <header>, <footer>, <menu>, <section>, etc. -- use them, don't be afraid.
Being fearless is the right attitude, but you still need to use them wisely. I recommend the resource https://html5doctor.com/ -- it has a really thorough breakdown of HTML5 spec additions.
And a couple more interesting resources for good measure:
https://developer.mozilla.org/ -- a reference for web developers
https://web.dev/explore -- there's a whole community here
Try to avoid redundant elements on the page. Most HTML pages are guilty of having unnecessary block elements:
<div id="header">
<div id="logo">
<h1><a href="/">My Blog</a></h1>
</div>
<div id="description">
<h2>Here I share my thoughts</h2>
</div>
</div>This structure can easily be simplified, making the code more readable, with minimal or even zero CSS changes required:
<header>
<h1>
<a href="/">My Blog</a>
</h1>
<h2>Here I share my thoughts</h2>
</header>In English there's a term "divitis" -- it's used to describe HTML markup with excessive use of divs for no good reason. Usually beginners fall into this trap, wrapping elements in divs just to apply CSS styles, which leads to divs multiplying like rabbits.
Another mandatory step for creating "proper" HTML is using class names and identifiers that clearly describe the element's content, rather than some styling detail. Here's an example:
red, green etc.
at some point you'll want to change the design via CSS -- and the element with class "red" will turn blue; or you'll be running around all the pages changing red to blue, only to start all over again later
wide, small etc.
wide today, and tomorrow?
h90w490
presumably an element with height 90px and width 490px; or am I wrong? and does this class even fit on a smartphone screen?
b_1, px_9
meaningless names that you'll forget by tomorrow
color1, color2, ...
sometimes seen in "skinned" sites, but such classes are born out of laziness
element1...20
this also happens and nothing good comes of it
And examples of proper naming:
logo, content
the logo, main content
menu, submenu
menu and submenu
even, odd
even and odd list items (though for such tasks it's easier to use CSS operators :nth-child(even) and :nth-child(odd), again because elements might shift around in the future)
navigation
page navigation
copyright
licensing information
There's one more thing -- HTML and CSS code formatting. I won't dwell on it, but all code in this book will be formatted with proper indentation, and hopefully that will rub off on your own work.
Almost forgot -- don't model your classes after things like
p-X,m-Xthat you'll see in Bootstrap or Tailwind. The "utility first" concept works great for CSS frameworks, but for development without them, such naming is uninformative.
Last updated