Dasmoto's Semantics Review!: Is this legal?

And by legal I mean good practice… :sweat_smile:

Hi everyone! For this project I used all the semantic tags learned in the semantics lesson. It turned out fine, I think:

My question is: I assigned CSS classes to some semantic tags. Is this good practice? What could I improve on?

This is the code I’m curious about:
I used the <header> tag instead of a <div> to assign a class.

<header class="header">
  <h1>Dasmoto's Arts & Crafts</h1>

A class for all the <figcaption> tags, so they’re not visible.

  <img src="resources/images/hacksaw.jpeg" alt="Hacksaw Brushes">
  <figcaption class="notVis">Hacksaw brushes</figcaption>

And for the “Staring at…” blue text, I assigned a class to the <strong> tag.

  Made of the highest quality oak [...]  <strong class="starting">Starting at $3.00 / brush.</strong>

Is assigning classes to semantic tags good practice? In other code I’ve seen, from this project and otherwise, everyone seems to be using just the <span> and <div> tags to apply classes.

Also, could hiding the <figcaption> tags be interpreted as some kind of cheating by the SEO engines?

I’d love to understand more about semantics and to know if my code is doing them correctly. Your help is very appreciated!

Hi, there.

You do not need to use the class “header” for the <header> element if doing purely for styling purposes, it is a little redundant if so.

This all depends on what you are trying to do. <strong> is an element that places importance on the text within. If you believe that the price is important and should be considered so, then by all means, use the <strong> element. But placing classes on a semantic element is not bad practice. If I have five <section>s on a page, it is much easier to style them with their own class than with a combo descendant selector.

There are different reasons and purposes where elements need to be hidden visually. One such purpose would be to include words or descriptive phrasing that a screen reader would need to give context to parts of a page where none would be otherwise. What you are describing sounds like SEO manipulation and is ethically a no-no.


And it would be detected as such by the algorithm and be detrimental to your ranking.

1 Like

Thanks for your feedback! I’m glad to know that it is possible to style semantics with CSS.

I see. It would probably be more useful to assign a class to <header> if say, in a bigger project, there were a lot of pages with different header types that actually needed different classes.

Thank you for the heads up! I did this because the spec didn’t show a description but I wanted to add semantics, so it was my way of “balancing” both. But I guess it would have been better to just leave the images with the alt text. I’m very glad that you’ve helped me discover this now and not me finding out later in an actual, real, important project. Cheers!