How to add CSS in a HTML file

 

css in html

Css stands for Cascading Style Sheets, it is used to style a document.
Html places the content and css styles it, for example in a building the
bricks would be html, css would be the decorations and javascript would
be the functionality of the building. To create a website 3 major languages
are needed, they are html, css and javascript. In this blog I will teach
you how to include css in html.
Did you know you can code css in html? yes, html has a tag from which
you can style your website in css without creating an additional
file. There are 3 ways to code css in html. The 3 ways are "Internal css",
"Inline css", "External css".
Before following the guide, we expect you to know a bit of
html and css, knowing html and css would be a great help. Even
if you don't you can still follow the images given below.



1. Internal css
To add css in html with Internal css you need to add the
"style" tag first do open and close brackets("<>") and in beetween
them write "style". Then once you have wrote your css code you can
close the tag by open and close brackets("<>") and in beetween
them write "/style".




2. Inline css
Instead of adding a tag you can define the style of the element
straight from the "style" attribute.
If you want to add style to multiple elements then
I suggest using the Internal method but if you want to add style
to less then 4-5 elements then Inline css would be the perfect way to choose
First select the element you
want to apply the style to, then add a "style=''" attribute in beetween
the single quotes write your code. The style attribute should be
placed after you are defining the element, it should be before the ending brackets
of the starting element.




3. External css
In this way you will create an additional file. If you are making
large projects and want to sort out different code then I suggest you
the External method. Since in external method we have 2 files
one for html and one for css. You have to
first go to the "head" section of your html file. There write
"link rel='stylesheet' href='example.css'" this code does not need
ending brackets.



** BONUS CONTENT**
Javascript in html
I just taught you how to include css in html but there's another topic to cover,
did you know that javascript can also be included in html. Html was made
so it supports all 3 web languages which are html, css and javascript.
Without html it would be really hard to create a website. To add javascript in
html there are 2 methods.
1st Method
Just like in internal css we add the "style" tag, like that we add
the "script" tag to include javascript in our html file. It exactly works
like internal css, the only difference is that in it you code javascript instead of css.




2nd Method
Just like in external css, we also add a another file to code javascript.
We first go to the body section of our html code and type "script src="myjsfile.js".
If you didn't understand don't worry here's a image of it.







Comments

Popular posts from this blog

how to rank number one on google

The Complete JavaScript Course (2022) From Zero to Expert!

Learn CSS | Lesson 1 | Making A File