Bootstrap provides classes such as text-left
(Alignment classes), text-lowercase
(Transformation classes) etc, which is the same as defining inline-styles (not technically, but logically).
In an alternative methodology such as bem
, it imposes that classes should reflect 'physical' blocks and elements, and their modifier (or the state of the element, such as active
, current
), and any styles should be applied purely in the CSS.
The Bootstrap approach seems like a poor separation of concern between structure and presentation, and goes against this W3C Tip for Webmasters.
This issue is echoed by many:
How does one use Bootstrap while still keeping the HTML markup semantic?
Bootstrap is the most popular HTML, CSS, and JS framework for developing responsive, mobile first projects on the web. On the other hand, Semantic UI is detailed as "A UI Component library implemented using a set of specifications designed around natural language".
One of the most important features of HTML5 is its semantics. Semantic HTML refers to syntax that makes the HTML more comprehensible by better defining the different sections and layout of web pages. It makes web pages more informative and adaptable, allowing browsers and search engines to better interpret content.
Certainly: you can still use <div> ! Despite HTML 5 bringing us new elements like <article> , <section> , and <aside> , the <div> element still has its place.
So some amount of semantic HTML definitely makes sense for SEO. It definitely makes sense for usability and for compatibility across different browser types, all of that as well.
Bootstrap provides mixins which you can use. So instead of adding classes like col-xs-12
in the HTML, you'd use @include make-xs-column(12)
inside the selector block for the element. To add a row, there's the @mixin make-row
.
Referring to an answer by Alexey Morashko, instead of this unsemantic markup:
<div class="items-list row"> <div class="item col-xs-12 col-sm-6 col-md-4"> <div class="item-name">Product first</div> <div class="item-description">Lorem ipsum dolor sit amet, consectetur adipisicing elit.</div> </div> <div class="item col-xs-12 col-sm-6 col-md-4"> <div class="item-name">Product second</div> <div class="item-description">Ratione, ullam, reprehenderit aliquid saepe ab harum.</div> </div> <div class="item col-xs-12 col-sm-6 col-md-4"> <div class="item-name">Product third</div> <div class="item-description"> totam repudiandae velit eum accusantium veritatis.</div> </div> </div>
You can instead use:
<div class="items-list"> <div class="item"> <div class="item-name">Product first</div> <div class="item-description">Lorem ipsum dolor sit amet, consectetur adipisicing elit.</div> </div> <div class="item"> <div class="item-name">Product second</div> <div class="item-description">Ratione, ullam, reprehenderit aliquid saepe ab harum.</div> </div> <div class="item"> <div class="item-name">Product third</div> <div class="item-description"> totam repudiandae velit eum accusantium veritatis.</div> </div> </div>
.items-list { @include make-row(); .item @include make-xs-column(12); @include make-sm-column(6); @include make-md-column(4); } }
You can find more examples of Bootstrap mixins in the Sitepoint article - 5 Useful Sass Mixins in Bootstrap.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With