Coming as a beginner into HTML can be difficult, especially for the amount
of default properties and behaviors that are in place and nobody tells you about it. In this article, I am going to show you how these things work, how you can modify their default behavior, and help you get a better understanding of HTML that will be useful any time there is a roadblock in the rendering of your page.
The rendering flow of elements inside an HTML document depends on a property called display, this property sets how the item is going to behave inside the page. There are two default values for all the elements: block and inline. Let's talk about block first, this property value sets the element to occupy all the available space in the same line. In other words, it generates a line break before and after the item so no other element renders next to it, making the next item in the code rendered below the block element.
As for inline property value, it makes the next element render where the previous one ends, creating a line of items if there is space available. However, they take only the necessary space to fit the content and their dimensions can’t be changed.
All the HTML elements have a default display value. Elements with the
block display property value include but are not limited to: <p>, <hx>, <div>, <ul>, <ol> and <form>. On the other hand, some of the elements with inline default value are: <span>, <a> and <img>. For the full list of
elements you can got the these websites for block elements and inline elements.
There are a variety of display properties that can be used to change the way you document is rendered. Some of them like flex or grid are a whole world on their own, but we will focus on the simpler ones that will help you to have better control over your elements.
As we said, the default for every HTML element goes between block or inline, but there is a third display property that combines the best of both worlds. The inline-block property will allow your element to behave like an inline element, meaning that other elements can be next to it, but it will also allow you to control its height and width so you can make it as big and wide as you want. This is extremely helpful especially when you want to put images next to text without using float.
But these are not the only properties that affect the flow of the document, you can also achieve that with the position property. With it, you can place your element wherever you want without worrying about if it is inline or block. This property can take 4 values:
Today we learned that the rendering of an HTML page is affected basically by two main properties: Display and Position, and their values determine how the elements are positioned in the document. I encourage you to tinker with them so you can use them in all your projects.
Thank you for reading this article all the way down to the end and I hope all the information presented here helped you to get a better understanding of how HTML works and will improve your building of
pages by understanding exactly why it is not rendering the way you expected it to.
Create your free account to unlock your custom reading experience.