0 added
0 removed
Original
2026-01-01
Modified
2026-03-09
1
<p>We already know that it is considered good practice to invoke styles using the <link> tag:</p>
1
<p>We already know that it is considered good practice to invoke styles using the <link> tag:</p>
2
<link rel="stylesheet" href="style.css"><p>But there is another way to invoke styles: by embedding them directly into a document instead of invoking them through links. Styles can be invoked either inside the <style> tag, or they can be written out as the value for in the style attribute of the HTML elements themselves.</p>
2
<link rel="stylesheet" href="style.css"><p>But there is another way to invoke styles: by embedding them directly into a document instead of invoking them through links. Styles can be invoked either inside the <style> tag, or they can be written out as the value for in the style attribute of the HTML elements themselves.</p>
3
<p>The option for invoking styles in the <style> tag is used most frequently to optimize the page load time. After all, in this case the browser will not have to send additional queries to the server. The <style> tag is usually placed inside <head>. For example:</p>
3
<p>The option for invoking styles in the <style> tag is used most frequently to optimize the page load time. After all, in this case the browser will not have to send additional queries to the server. The <style> tag is usually placed inside <head>. For example:</p>
4
<head> <style> CSS code </style> </head><p>The second option for embedding styles is through the contents of the style attribute. The properties and values that are assigned in this way will be applied to just a single element:</p>
4
<head> <style> CSS code </style> </head><p>The second option for embedding styles is through the contents of the style attribute. The properties and values that are assigned in this way will be applied to just a single element:</p>
5
<div style="width: 50%;"></div><p>Usually, using this method is considered to be bad practice because it’s harder to maintain when some styles are in a stylesheet and others are mixed in with the HTML. However, in exceptional cases it is sometimes more convenient to embed styles in a style attribute than to write out separate CSS rules. For example, when you need to manage styles from the markup itself, it is not necessary to create separate classes. This happens when some style parameters are assigned using third-party programs or by other people, such as, for example, through a Content Management System.</p>
5
<div style="width: 50%;"></div><p>Usually, using this method is considered to be bad practice because it’s harder to maintain when some styles are in a stylesheet and others are mixed in with the HTML. However, in exceptional cases it is sometimes more convenient to embed styles in a style attribute than to write out separate CSS rules. For example, when you need to manage styles from the markup itself, it is not necessary to create separate classes. This happens when some style parameters are assigned using third-party programs or by other people, such as, for example, through a Content Management System.</p>
6
<p>Let’s take a closer look at the example with style="width: 50%;". Let’s suppose that you need to be able to control the width using the property width within a range of 0% to 100% in the markup. To do this through CSS, you would have to create 100 classes and assign them as follows:</p>
6
<p>Let’s take a closer look at the example with style="width: 50%;". Let’s suppose that you need to be able to control the width using the property width within a range of 0% to 100% in the markup. To do this through CSS, you would have to create 100 classes and assign them as follows:</p>
7
.width-0 { width: 0% } .width-1 { width: 1% } .width-2 { width: 2% } /* etc… */<p>It is much more convenient to pinpoint the assignment of a style specifying width in the style attribute.</p>
7
.width-0 { width: 0% } .width-1 { width: 1% } .width-2 { width: 2% } /* etc… */<p>It is much more convenient to pinpoint the assignment of a style specifying width in the style attribute.</p>
8
<p>Let’s use this method to apply styles to our visual indicator of the progress that we made in learning new skills.</p>
8
<p>Let’s use this method to apply styles to our visual indicator of the progress that we made in learning new skills.</p>
9
<p>You can access the intermediate version of our website at this<a>link</a>.</p>
9
<p>You can access the intermediate version of our website at this<a>link</a>.</p>