Semantic markup for card blocks
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
2
down vote
favorite
I'm using Bootstrap. I'm doing my best to work with more semantic markup and getting away from divitis.
Several of these "card" blocks appear on a page, like this.
Original:
<div class="col-lg-4 mb-4">
<div class="card h-100">
<h4 class="card-header">Card Title</h4>
<div class="card-body">
<p class="card-text">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Reiciendis ipsam eos, nam perspiciatis natus commodi similique totam consectetur praesentium molestiae atque exercitationem ut consequuntur, sed eveniet, magni nostrum sint fuga.</p>
</div>
<div class="card-footer">
<a href="#" class="btn btn-primary">Learn More</a>
</div>
</div>
</div>
Rewritten:
<section class="col-lg-4 mb-4">
<div class="card h-100">
<header>
<h4 class="card-header">Card Title</h4>
</header>
<section class="card-body">
<p class="card-text">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Sapiente esse necessitatibus neque.</p>
</section>
<footer class="card-footer">
<a href="#" class="btn btn-primary">Learn More</a>
</footer>
</div>
</section>
Could I improve the HTML?
html comparative-review html5 twitter-bootstrap
add a comment |Â
up vote
2
down vote
favorite
I'm using Bootstrap. I'm doing my best to work with more semantic markup and getting away from divitis.
Several of these "card" blocks appear on a page, like this.
Original:
<div class="col-lg-4 mb-4">
<div class="card h-100">
<h4 class="card-header">Card Title</h4>
<div class="card-body">
<p class="card-text">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Reiciendis ipsam eos, nam perspiciatis natus commodi similique totam consectetur praesentium molestiae atque exercitationem ut consequuntur, sed eveniet, magni nostrum sint fuga.</p>
</div>
<div class="card-footer">
<a href="#" class="btn btn-primary">Learn More</a>
</div>
</div>
</div>
Rewritten:
<section class="col-lg-4 mb-4">
<div class="card h-100">
<header>
<h4 class="card-header">Card Title</h4>
</header>
<section class="card-body">
<p class="card-text">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Sapiente esse necessitatibus neque.</p>
</section>
<footer class="card-footer">
<a href="#" class="btn btn-primary">Learn More</a>
</footer>
</div>
</section>
Could I improve the HTML?
html comparative-review html5 twitter-bootstrap
2
Welcome to Code Review. It's hard to judge what is appropriate semantic markup based on Lorem Ipsum text with no explanation of what the code is supposed to accomplish or how it fits into the rest of the document.
â 200_success
Mar 1 at 14:54
@200_success I edited my question. There is not supposed to be much of a context. Really, it is just about the code and nothing else.
â user162026
Mar 1 at 15:00
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I'm using Bootstrap. I'm doing my best to work with more semantic markup and getting away from divitis.
Several of these "card" blocks appear on a page, like this.
Original:
<div class="col-lg-4 mb-4">
<div class="card h-100">
<h4 class="card-header">Card Title</h4>
<div class="card-body">
<p class="card-text">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Reiciendis ipsam eos, nam perspiciatis natus commodi similique totam consectetur praesentium molestiae atque exercitationem ut consequuntur, sed eveniet, magni nostrum sint fuga.</p>
</div>
<div class="card-footer">
<a href="#" class="btn btn-primary">Learn More</a>
</div>
</div>
</div>
Rewritten:
<section class="col-lg-4 mb-4">
<div class="card h-100">
<header>
<h4 class="card-header">Card Title</h4>
</header>
<section class="card-body">
<p class="card-text">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Sapiente esse necessitatibus neque.</p>
</section>
<footer class="card-footer">
<a href="#" class="btn btn-primary">Learn More</a>
</footer>
</div>
</section>
Could I improve the HTML?
html comparative-review html5 twitter-bootstrap
I'm using Bootstrap. I'm doing my best to work with more semantic markup and getting away from divitis.
Several of these "card" blocks appear on a page, like this.
Original:
<div class="col-lg-4 mb-4">
<div class="card h-100">
<h4 class="card-header">Card Title</h4>
<div class="card-body">
<p class="card-text">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Reiciendis ipsam eos, nam perspiciatis natus commodi similique totam consectetur praesentium molestiae atque exercitationem ut consequuntur, sed eveniet, magni nostrum sint fuga.</p>
</div>
<div class="card-footer">
<a href="#" class="btn btn-primary">Learn More</a>
</div>
</div>
</div>
Rewritten:
<section class="col-lg-4 mb-4">
<div class="card h-100">
<header>
<h4 class="card-header">Card Title</h4>
</header>
<section class="card-body">
<p class="card-text">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Sapiente esse necessitatibus neque.</p>
</section>
<footer class="card-footer">
<a href="#" class="btn btn-primary">Learn More</a>
</footer>
</div>
</section>
Could I improve the HTML?
html comparative-review html5 twitter-bootstrap
edited Mar 2 at 10:14
Billal BEGUERADJ
1
1
asked Mar 1 at 14:44
user162026
2
Welcome to Code Review. It's hard to judge what is appropriate semantic markup based on Lorem Ipsum text with no explanation of what the code is supposed to accomplish or how it fits into the rest of the document.
â 200_success
Mar 1 at 14:54
@200_success I edited my question. There is not supposed to be much of a context. Really, it is just about the code and nothing else.
â user162026
Mar 1 at 15:00
add a comment |Â
2
Welcome to Code Review. It's hard to judge what is appropriate semantic markup based on Lorem Ipsum text with no explanation of what the code is supposed to accomplish or how it fits into the rest of the document.
â 200_success
Mar 1 at 14:54
@200_success I edited my question. There is not supposed to be much of a context. Really, it is just about the code and nothing else.
â user162026
Mar 1 at 15:00
2
2
Welcome to Code Review. It's hard to judge what is appropriate semantic markup based on Lorem Ipsum text with no explanation of what the code is supposed to accomplish or how it fits into the rest of the document.
â 200_success
Mar 1 at 14:54
Welcome to Code Review. It's hard to judge what is appropriate semantic markup based on Lorem Ipsum text with no explanation of what the code is supposed to accomplish or how it fits into the rest of the document.
â 200_success
Mar 1 at 14:54
@200_success I edited my question. There is not supposed to be much of a context. Really, it is just about the code and nothing else.
â user162026
Mar 1 at 15:00
@200_success I edited my question. There is not supposed to be much of a context. Really, it is just about the code and nothing else.
â user162026
Mar 1 at 15:00
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
2
down vote
200_success' comment is right, that the context and the content of the component is important for semantics. I assume, from the linked page, that you want to display a list of short articles that lead to more detailed information.
That being said. Let's look at your rewrite:
Outer section
-element.
While a section
might be fine, to me this looks more like a list of short articles. So I would use an article
-element here.
The article element represents a self-contained composition in a document, page, application, or site and that is, in principle, independently distributable or reusable, e.g. in syndication. This could be a forum post, a magazine or newspaper article, a blog entry, a user-submitted comment, an interactive widget or gadget, or any other independent item of content.
From w3.org 4.4.4 The article element
Also interesting on Stackoverflow: Semantic HTML of an articles list
header
-element
If you only have a heading
-element and no other content for the the header of a sectioning-element, you should drop the extra header
-element, as:
These elements [h1 ⦠h6] represent headings for their sections.
From w3.org 4.3.6 The h1, h2, h3, h4, h5, and h6 elements
Nested section
-element
The paragraph is the actual content of this item. Its context is not a standalone section, as implied, when wrapping it in another section
-element:
The HTML element represents a standalone section
From MDN <section>
: The Generic Section element
So drop that section
as well.
footer
-element
Using a footer
-element here is debatable (as all other points as well). From the docs point of view it's absolutely fine:
A footer typically contains information about its section such as who wrote it, links to related documents, copyright data, and the like.
From w3.org 4.4.9 The footer element
However, personally I would drop it for simplicity.
Finally we remove everything that is not needed for styling â in regard of your linked layout â and end up with this:
<article>
<h1>Card heading</h1>
<p>Some teaser â¦</p>
<a href="">Learn more â¦</a>
</article>
add a comment |Â
up vote
1
down vote
The one observation I have, is that the two outer elements should be swapped:
The outer section
has no semantic use, it just contains layout classes. On the other hand the actual card, that does have semantic meaning, but it is just a div
. I'd swap them:
<div class="col-lg-4 mb-4">
<section class="card h-100">
<!-- ... -->
</section>
</div>
interesting. I must keep that in mind semantic meaning vs no semantic meaning
â user162026
Mar 1 at 16:05
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
200_success' comment is right, that the context and the content of the component is important for semantics. I assume, from the linked page, that you want to display a list of short articles that lead to more detailed information.
That being said. Let's look at your rewrite:
Outer section
-element.
While a section
might be fine, to me this looks more like a list of short articles. So I would use an article
-element here.
The article element represents a self-contained composition in a document, page, application, or site and that is, in principle, independently distributable or reusable, e.g. in syndication. This could be a forum post, a magazine or newspaper article, a blog entry, a user-submitted comment, an interactive widget or gadget, or any other independent item of content.
From w3.org 4.4.4 The article element
Also interesting on Stackoverflow: Semantic HTML of an articles list
header
-element
If you only have a heading
-element and no other content for the the header of a sectioning-element, you should drop the extra header
-element, as:
These elements [h1 ⦠h6] represent headings for their sections.
From w3.org 4.3.6 The h1, h2, h3, h4, h5, and h6 elements
Nested section
-element
The paragraph is the actual content of this item. Its context is not a standalone section, as implied, when wrapping it in another section
-element:
The HTML element represents a standalone section
From MDN <section>
: The Generic Section element
So drop that section
as well.
footer
-element
Using a footer
-element here is debatable (as all other points as well). From the docs point of view it's absolutely fine:
A footer typically contains information about its section such as who wrote it, links to related documents, copyright data, and the like.
From w3.org 4.4.9 The footer element
However, personally I would drop it for simplicity.
Finally we remove everything that is not needed for styling â in regard of your linked layout â and end up with this:
<article>
<h1>Card heading</h1>
<p>Some teaser â¦</p>
<a href="">Learn more â¦</a>
</article>
add a comment |Â
up vote
2
down vote
200_success' comment is right, that the context and the content of the component is important for semantics. I assume, from the linked page, that you want to display a list of short articles that lead to more detailed information.
That being said. Let's look at your rewrite:
Outer section
-element.
While a section
might be fine, to me this looks more like a list of short articles. So I would use an article
-element here.
The article element represents a self-contained composition in a document, page, application, or site and that is, in principle, independently distributable or reusable, e.g. in syndication. This could be a forum post, a magazine or newspaper article, a blog entry, a user-submitted comment, an interactive widget or gadget, or any other independent item of content.
From w3.org 4.4.4 The article element
Also interesting on Stackoverflow: Semantic HTML of an articles list
header
-element
If you only have a heading
-element and no other content for the the header of a sectioning-element, you should drop the extra header
-element, as:
These elements [h1 ⦠h6] represent headings for their sections.
From w3.org 4.3.6 The h1, h2, h3, h4, h5, and h6 elements
Nested section
-element
The paragraph is the actual content of this item. Its context is not a standalone section, as implied, when wrapping it in another section
-element:
The HTML element represents a standalone section
From MDN <section>
: The Generic Section element
So drop that section
as well.
footer
-element
Using a footer
-element here is debatable (as all other points as well). From the docs point of view it's absolutely fine:
A footer typically contains information about its section such as who wrote it, links to related documents, copyright data, and the like.
From w3.org 4.4.9 The footer element
However, personally I would drop it for simplicity.
Finally we remove everything that is not needed for styling â in regard of your linked layout â and end up with this:
<article>
<h1>Card heading</h1>
<p>Some teaser â¦</p>
<a href="">Learn more â¦</a>
</article>
add a comment |Â
up vote
2
down vote
up vote
2
down vote
200_success' comment is right, that the context and the content of the component is important for semantics. I assume, from the linked page, that you want to display a list of short articles that lead to more detailed information.
That being said. Let's look at your rewrite:
Outer section
-element.
While a section
might be fine, to me this looks more like a list of short articles. So I would use an article
-element here.
The article element represents a self-contained composition in a document, page, application, or site and that is, in principle, independently distributable or reusable, e.g. in syndication. This could be a forum post, a magazine or newspaper article, a blog entry, a user-submitted comment, an interactive widget or gadget, or any other independent item of content.
From w3.org 4.4.4 The article element
Also interesting on Stackoverflow: Semantic HTML of an articles list
header
-element
If you only have a heading
-element and no other content for the the header of a sectioning-element, you should drop the extra header
-element, as:
These elements [h1 ⦠h6] represent headings for their sections.
From w3.org 4.3.6 The h1, h2, h3, h4, h5, and h6 elements
Nested section
-element
The paragraph is the actual content of this item. Its context is not a standalone section, as implied, when wrapping it in another section
-element:
The HTML element represents a standalone section
From MDN <section>
: The Generic Section element
So drop that section
as well.
footer
-element
Using a footer
-element here is debatable (as all other points as well). From the docs point of view it's absolutely fine:
A footer typically contains information about its section such as who wrote it, links to related documents, copyright data, and the like.
From w3.org 4.4.9 The footer element
However, personally I would drop it for simplicity.
Finally we remove everything that is not needed for styling â in regard of your linked layout â and end up with this:
<article>
<h1>Card heading</h1>
<p>Some teaser â¦</p>
<a href="">Learn more â¦</a>
</article>
200_success' comment is right, that the context and the content of the component is important for semantics. I assume, from the linked page, that you want to display a list of short articles that lead to more detailed information.
That being said. Let's look at your rewrite:
Outer section
-element.
While a section
might be fine, to me this looks more like a list of short articles. So I would use an article
-element here.
The article element represents a self-contained composition in a document, page, application, or site and that is, in principle, independently distributable or reusable, e.g. in syndication. This could be a forum post, a magazine or newspaper article, a blog entry, a user-submitted comment, an interactive widget or gadget, or any other independent item of content.
From w3.org 4.4.4 The article element
Also interesting on Stackoverflow: Semantic HTML of an articles list
header
-element
If you only have a heading
-element and no other content for the the header of a sectioning-element, you should drop the extra header
-element, as:
These elements [h1 ⦠h6] represent headings for their sections.
From w3.org 4.3.6 The h1, h2, h3, h4, h5, and h6 elements
Nested section
-element
The paragraph is the actual content of this item. Its context is not a standalone section, as implied, when wrapping it in another section
-element:
The HTML element represents a standalone section
From MDN <section>
: The Generic Section element
So drop that section
as well.
footer
-element
Using a footer
-element here is debatable (as all other points as well). From the docs point of view it's absolutely fine:
A footer typically contains information about its section such as who wrote it, links to related documents, copyright data, and the like.
From w3.org 4.4.9 The footer element
However, personally I would drop it for simplicity.
Finally we remove everything that is not needed for styling â in regard of your linked layout â and end up with this:
<article>
<h1>Card heading</h1>
<p>Some teaser â¦</p>
<a href="">Learn more â¦</a>
</article>
answered Mar 2 at 10:01
insertusernamehere
1,616716
1,616716
add a comment |Â
add a comment |Â
up vote
1
down vote
The one observation I have, is that the two outer elements should be swapped:
The outer section
has no semantic use, it just contains layout classes. On the other hand the actual card, that does have semantic meaning, but it is just a div
. I'd swap them:
<div class="col-lg-4 mb-4">
<section class="card h-100">
<!-- ... -->
</section>
</div>
interesting. I must keep that in mind semantic meaning vs no semantic meaning
â user162026
Mar 1 at 16:05
add a comment |Â
up vote
1
down vote
The one observation I have, is that the two outer elements should be swapped:
The outer section
has no semantic use, it just contains layout classes. On the other hand the actual card, that does have semantic meaning, but it is just a div
. I'd swap them:
<div class="col-lg-4 mb-4">
<section class="card h-100">
<!-- ... -->
</section>
</div>
interesting. I must keep that in mind semantic meaning vs no semantic meaning
â user162026
Mar 1 at 16:05
add a comment |Â
up vote
1
down vote
up vote
1
down vote
The one observation I have, is that the two outer elements should be swapped:
The outer section
has no semantic use, it just contains layout classes. On the other hand the actual card, that does have semantic meaning, but it is just a div
. I'd swap them:
<div class="col-lg-4 mb-4">
<section class="card h-100">
<!-- ... -->
</section>
</div>
The one observation I have, is that the two outer elements should be swapped:
The outer section
has no semantic use, it just contains layout classes. On the other hand the actual card, that does have semantic meaning, but it is just a div
. I'd swap them:
<div class="col-lg-4 mb-4">
<section class="card h-100">
<!-- ... -->
</section>
</div>
answered Mar 1 at 15:57
RoToRa
6,0121236
6,0121236
interesting. I must keep that in mind semantic meaning vs no semantic meaning
â user162026
Mar 1 at 16:05
add a comment |Â
interesting. I must keep that in mind semantic meaning vs no semantic meaning
â user162026
Mar 1 at 16:05
interesting. I must keep that in mind semantic meaning vs no semantic meaning
â user162026
Mar 1 at 16:05
interesting. I must keep that in mind semantic meaning vs no semantic meaning
â user162026
Mar 1 at 16:05
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f188612%2fsemantic-markup-for-card-blocks%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
2
Welcome to Code Review. It's hard to judge what is appropriate semantic markup based on Lorem Ipsum text with no explanation of what the code is supposed to accomplish or how it fits into the rest of the document.
â 200_success
Mar 1 at 14:54
@200_success I edited my question. There is not supposed to be much of a context. Really, it is just about the code and nothing else.
â user162026
Mar 1 at 15:00