Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprenda Element Types | Box Model and Element Spacing
CSS Fundamentals

book
Element Types

Elements can be classified as inline or block elements, and the distinction lies in their default behavior.

  • Inline elements typically do not start on a new line and only take up as much width as necessary. They allow other elements to sit beside them on the same line;
  • Block elements, on the other hand, typically start on a new line and extend the full width of their container. They create a new "block" or "box" for content.

Block elements

Block elements occupy the entire width of their parent container and typically begin on a new line. Examples of block elements encompass <div>, <h1> through <h6>, <p>, <ul>, <ol>, <li>, and various others. These elements can have their width, height, margin, padding, and border properties customized using CSS.

html

index.html

css

index.css

copy
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="index.css" />
</head>
<body>
<ol>
<li><p>Lorem ipsum dolor sit amet.</p></li>
<li><p>Lorem ipsum</p></li>
<li><p>Lorem ipsum dolor sit amet.</p></li>
</ol>
<ul>
<li><h4>Lorem, ipsum.</h4></li>
<li><h4>Lorem, ipsum dolor.</h4></li>
<li><h4>Lorem, ipsum dolor.</h4></li>
</ul>
</body>
</html>

Inline elements

Inline elements do not initiate a new line and only occupy the width essential for their content. Examples of inline elements encompass <a>, <span>, <img>, <input>, and several others. Unlike block elements, inline elements cannot be assigned specific values for height, width, margin, or padding using CSS. However, it's worth noting that border can be applied to inline elements.

html

index.html

css

index.css

copy
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="index.css" />
</head>
<body>
<input type="number" />
<span>Lorem, ipsum dolor.</span>
<a href="#">Lorem, ipsum.</a>
<span>Lorem ipsum dolor sit amet consectetur.</span>
</body>
</html>

Inline-block elements

In addition to block and inline elements, there exists a third category known as inline-block elements. Similar to inline elements, inline-block elements do not initiate a new line and occupy just enough width for their content. What sets them apart is their ability to have height, width, margin, padding, and border properties specified using CSS. Examples of inline-block elements include <button>, <select>, and <textarea>.

html

index.html

css

index.css

copy
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="index.css" />
</head>
<body>
<button type="button" class="send-btn">Send request</button>
<button type="submit" class="submit-btn">Submit form</button>
</body>
</html>

1. What is the main difference between block and inline elements?

2. Which of the following is an example of a block element?

question mark

What is the main difference between block and inline elements?

Selecione a resposta correta

question mark

Which of the following is an example of a block element?

Selecione a resposta correta

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 3. Capítulo 7
some-alt