HTML <article> Tag
The <article> tag is one of the HTML5 elements. It is used to define an independent, self-contained content. An article should have its own meaning and be easily differentiated from the rest of the web page content.
The <article> element can include:
- blog entry
- forum post
Multiple <article> tags can be used in one HTML document.
The content of the <article> tag is written between the opening (<article>) and the closing (</article>) tags.
Headers from <h2> to <h6> can be nested inside the <article> tag. If the <h1> tag was not used before, then its placement is allowed.
<html> <head> <title>Title of the document</title> </head> <body> <article> <h1>Title of the article</h1> <p>Text of the article</p> </article> </body> </html>
Let’s consider another example, where there are multiple <article> tags in a <section> element.
<html> <head> <title>Title of the document</title> </head> <body> <section> <h1>Articles about flowers</h1> <article> <h2>Roses</h2> <p>Rose – the queen of flowers - is the object of worship and ardent love. Since time immemorial, the rose has been the object of worship and admiration.</p> </article> <article> <h2>Lilies</h2> <p> Lily - an amazing beauty flower, one of the most ancient among a variety of bulbous plants. </p> </article> </section> </body> </html>
How to style <article> tag?
Common properties to alter the visual weight/emphasis/size of text in <article> tag:
- CSS font-style property sets the style of the font. normal | italic | oblique | initial | inherit.
- CSS font-family property specifies a prioritized list of one or more font family names and/or generic family names for the selected element.
- CSS font-size property sets the size of the font.
- CSS font-weight property defines whether the font should be bold or thick.
- CSS text-transform Property controls text case and capitalization.
- CSS text-decoration property specifies the decoration added to text, and is a shorthand property for text-decoration-line, text-decoration-color, text-decoration-style.
Coloring text in <article> tag:
- CSS color property describes the color of the text content and text decorations.
- CSS background-color property sets the background color of an element.
Text layout styles for <article> tag:
- CSS text-indent property specifies the indentation of the first line in a text block.
- CSS text-overflow property specifies how overflowed content that is not displayed should be signalled to the user.
- CSS white-space property specifies how white-space inside an element is handled.
- CSS word-break property specifies where the lines should be broken.
Other properties worth looking at for <article> tag:
- CSS text-shadow property adds shadow to text.
- CSS text-align-last property sets the alignment of the last line of the text.
- CSS line-height property specifies the height of a line.
- CSS letter-spacing property defines the spaces between letters/characters in a text.
- CSS word-spacing property sets the spacing between words.