HTML Block and Inline Elements
Every HTML element has a default display value depending on what type of element it is. The default display value for most elements is block or inline.
Block-level Elements
A block-level element always starts on a new line and takes up the full width available (stretches out to the left and right as far as it can).
"The <div> element is a block-level element."
Examples of block-level elements:
- <div>
- <h1> - <h6>
- <p>
- <form>
Inline Elements
An inline element does not start on a new line and only takes up as much width as necessary.
This is an inline <span> element inside a paragraph.
Examples of inline elements:
- <span>
- <a>
- <img>
The <div> Element
The <div> element is often used as a container for other HTML elements.
The <div> element has no required attributes, but both style and class are common.
When used together with CSS, the <div> element can be used to style blocks of content:
Example
<!DOCTYPE html>
<html>
<body>
<div style="background-color:blue;color:white;padding:20px;">
<h1>Germany</h1>
<p>In 1871, Germany became a nation state when most of the German states unified into the Prussian-dominated German Empire. After World War I and the German Revolution of 1918–1919, the Empire was replaced by the parliamentary Weimar Republic.</p>
<p> In 1933 the Nazi seizure of power quickly led to the establishment of Nazi Germany which was built upon a dictatorship and consequently led to World War II and the Holocaust. After the end of World War II in Europe and a period of Allied occupation, two German states were founded: the democratic West Germany and the socialist East Germany. On 3 October 1990, the country was reunified.</p>
</div>
</body>
</html>
The <span> Element
The <span> element is often used as a container for some text.
The <span> element has no required attributes, but both style and class are common.
When used together with CSS, the <span> element can be used to style parts of the text:
Example
<!DOCTYPE html>
<html>
<body>
<h1>My <span style="color:Blue">Personal</span> Heading</h1>
</body>
</html>
Results
HTML Grouping Tags
Tag | Description |
---|---|
<div> | Defines a section in a document (block-level) |
<span> | Defines a section in a document (inline) |
Comments
Post a Comment