CSS methods

The CSS properties can be written either in the style attribute of a tag or in the <style> element.

There are three methods to apply CSS properties to an element.

  • inline CSS
  • internal CSS
  • external CSS

1. inline CSS

In this method, style attribute is used in the starting tag of the element that we want to style. The syntax of inline CSS has been given below.


<E style="property-name:property-value;"></E>
<div style="width:400px; height:400px; background-color:lightblue;"></div>

Try </>

In the above example, style attribute contains the CSS properties. One property includes the property-name and property-value. For example, width is the property-name and 400px is the property-value (width:400px;).

2. internal CSS

In this method, CSS properties are specified in the <style> tag. And the <style> must be present in the <head> tag. See the syntax given below for the internal CSS properties.



Try </>

The above given inline and internal methods apply the same CSS properties.

3. external CSS

In this method, a separate file of CSS is used to style the content. To make a css file

  • Copy the above given code and paste it in the notepad. Now, save the file with the name external.css.

  • Remember that you can give any name to the file but the extension must be .css.

  • And now connect CSS file with the HTML using <style> tag. And in this case, <style> tag may be placed inside the head or body sections.

The syntax to import a CSS file is given below.


<link href="external.css" rel="stylesheet">

Try </>

rel means relation. And the value of rel is stylesheet because external.css is a style sheet.

Was this article helpful?