Setup and Syntax
CSS can be written in an HTML document using the internal stylesheet. The internal stylesheet is situated between head tags in the HTML document.
You can use this technique when you want to apply styles to a specific page.
The above code shows how to declare an internal stylesheet in HTML. The
style element is located in the head part of the HTML document that contains CSS rules/ruleset.
The only difference is the absence of the
link tag that we used to link the stylesheet in our HTML document.
In this example, we established styles for the
p elements using specific CSS properties. We can say that the rules will apply to all
p elements in the document.
Let's move the inline style that was added to the paragraph into an internal stylesheet.
Start by adding an empty
<style> element in the head of
Inside of the
<style> element, add a CSS ruleset targeting the paragraph (the
<p> element). You can leave the declaration block empty for now
Next, place just the declaration from the inline style into the empty declaration block in the inline stylesheet.
Finally, delete the inline style from the
Notice how the styling works the same in the stylesheet as it did in the inline style!
Sign up to start coding
Already have an account?