×

Internal CSS

What is CSS?

  • CSS stands for Cascading Style Sheet.
  • CSS is used to apply styling the HTML elements.
  • With CSS user can add or change color, font-size and font-family. It also helps user to add margins or padding to different HTML elements.
  • CSS helps user to make the HTML elements or front end look more elegant.

There are 3 different ways to add/apply CSS into the HTML pages-

  1. Internal CSS
  2. External CSS
  3. Inline CSS

Let’s take a look on these three different ways to add CSS.

Internal CSS

<style> tag is used to add internal CSS in HTML page. Internal CSS apply to the all elements present in the <style> tag.

<style> tag is used within <head> tag of HTML page.

Syntax:

<head> 
<style type="text/css">
HTML_tag_element{ 
  CSS property code
}
</style>
</head>

For Example,

<head>
<style>
p{
 color: red;
font-family: Segoe UI Black;
 font-size: 50px;
}
</style>
<body><p>An example with CSS</p></body>

In above code, internal CSS applied to the <p> tag of HTML page where we applied the color, font-family, and font size properties. And this CSS makes simple <p> tag element look better and elegant. And this is how user can use internal CSS to apply styling to <p> tag and other html tags also.

Output:

Internal CSS

External CSS

In case of internal CSS styling is applies to only one HTML page and within that page only.
In order to apply styling to all HTML pages present in the project, external CSS is used.
In external CSS, an external CSS file is maintained which contains the code that applies styling to all HTML files.

<link> tag is used in HTML page to apply CSS styling to the current HTML page

Ex. <link rel=”stylesheet” type=”text/css” href=”style.css”>

Example:

Demo.html
<head>
<link rel=”stylesheet” type=”text/css” href=”style.css”>
</head>
<body><p> An example with CSS in Demo file</p></body>


Demo2.html
<head>
<link rel=”stylesheet” type=”text/css” href=”style.css”>
</head>
<body><p> An example with CSS in Demo2 file</p></body>


Style.css
p{
   color: red;
   font-family: Segoe UI Black;
   font-size: 50px; 
}

In above code, separate style.css is written to style the all HTML files. And we apply this styling to 2 files namely Demo.html and Demo2.html using <link> tag.

Output:

Internal CSS

Inline CSS

Inline CSS is used to apply styling to specific HTML element

<style> tag is used within the html element just like the internal CSS

Syntax

<html_tag style=”property1:value;property2:value;”></html_tag>
Ex.
<p style=”color:red;font-family: Segoe UI Black;font-size: 50px;”>An example with CSS</p> 
<p>An example without CSS</p>

Output:

Internal CSS

The output of all three types of CSS adding methods is same but the method of adding is different and which is to be used depends on the user needs.

Coding Examples of Internal CSS

Let’s discuss some coding examples on Internal CSS.

Example 1

<!DOCTYPE html>
<html>
<head>
	<title></title>
	<style type="text/css">
		body{
			background-color: #DC8B8B
		}
		p {
			background-color: #B4F1DC;
			font-size: 20px;
		}
	</style>
</head>
<body>
    <h2>An Internal CSS Example 2</h2>
    <p>CSS stands for Cascading Style Sheet. CSS is used to apply styling the HTML elements. With CSS user can add or change color, font-size and font-family. Also it helps user to add margins or padding to different HTML elements.CSS helps user to make the HTML elements or front end look more elegant. </p>
</p>
</body>
</html>

Output:

Internal CSS

In above code, internal CSS is applied to <p> and <body> tags. Here, the background color property is applied to the body tag and again same property is applied to <p> tag. The <p> tag contains a different background color than <body> tag.         

Example 2

<!DOCTYPE html>
<html>
<head>
	<title></title>
	<style type="text/css">
		h1{
			color: red;
			margin-left: 50px;
			font-family: Verdana;
		}
		h2{
			color: cyan;
		}
		h3{
			color: blue;
		}
	</style>
</head>
<body>
    <h1>Heading 1</h1>
    <h2>Heading 2</h2>
    <h3>Heading 3</h3>
</body>
</body>
</html>

Output:

Internal CSS

Here, color property applied to <h1>, <h2> and <h3> tags. And <h1> tag has margin-left property and because of that <h1> element is placed on the page by putting 50px margin.

Example 3

<!DOCTYPE html>
<html>
<head>
	<title></title>
	<style type="text/css">
		img{
			width: 500px;
			height: 400px;
			margin-left: 50px;
			border: 3px solid black;
		}
		h1{
			margin-left: 50px;
		}
	</style>
</head>
<body>
   <h1>CSS styling to Image</h1>
   <img src="image1.png">
</body>
</html>

Output:

Internal CSS

It demonstrates CSS properties to image element. Here we set the width and height properties to an image and applied the 3px solid border to an image and the color of border is black. The margin-left property is applied to <img> and <h1> elements.


Related Topics

CSS Order

CSS Order CSS order property in CSS describes the flex item’s order inside the flex or any grid container. It is applied to order any flex item. Note: If any component is...

3 minutes read.

CSS Text-stroke

Text-stroke Text-stroke CSS property inserts the stroke to any text and gives a decoration option to them also. It describes the stroke’s width and color for various text characters. It is...

2 minutes read.

CSS Margin

CSS Margin: The CSS margin property is employed to describe the space throughout the elements. It clears the range throughout the element. These properties do not have a background color...

2 minutes read.

CSS Sticky

CSS Sticky The position property in CSS is applied to set an element’s position. This property is also applied to position an element behind the other element. It is useful for...

1 minute read.

CSS Introduction

CSS stands for Cascading Style Sheet. It is a design language which is used to design the web pages. It was developed by Håkon Wium Lie on October 10, 1994. It provides...

1 minute read.

What is Bootstrap CSS?

Bootstrap: - Bootstrap is a CSS framework that is free to use and is used for the front-end development of the website in a faster and easier way. Bootstrap was released as...

3 minutes read.

Create a 3D text effect using HTML and CSS

A3D text effect is a beautiful and attractive part of a webpage. As a web page developer, it is crucial to know how to create a 3D text effect with...

3 minutes read.

Css Text Orientation

Introduction: The text-orientation property of CSS is used to specify the orientation of the text characters in the line of content. This property applies only with the vertical writing-mode and not...

4 minutes read.

CSS Word-spacing

Word-spacing The work-spacing property of CSS is applied to manage the space among the words. We can decrease or increase the space among the words by the use of this property. It...

3 minutes read.

CSS Gradient

CSS Gradient: The CSS gradient property is applied to show the smooth transition inside two specified colors or more than two specified colors. Need of CSS Gradient The following are a few...

4 minutes read.

CSS Units

CSS Units In CSS, there are so many units available to show the length’s measurement. A single unit of CSS is applied to examine the size of the property, which the...

5 minutes read.

CSS z-index Property

CSS z-index: CSS z-index permits us to represent any visual hierarchy over a 3D plane that is the z-axis. This index can be applied to describe the positioned element’s stacking...

2 minutes read.

CSS Vertical Align

Vertical Align The vertical align CSS property describes the cell box of the table and an inline alignment vertically. This property is a self-explanatory and an essential property in CSS. But,...

2 minutes read.

What is CSS

CSS stands for Cascading Style Sheet. It gives an additional style to the HTML document. A cascading style sheet is a language that is designed to define the document formatting...

3 minutes read.

CSS Navigation bar

CSS Navigation bar: A navigation system or navigation bar comes upon GUI that can help many visitors to access the information. A Navigation bar is a UI component on the...

11 minutes read.

Grid Vs Flexbox in CSS

Grid: - CSS Grid Layout is a 2D grid-based matrix-based layout method with columns and rows that simplifies web pages created by eliminating the need for floats and placement. A grid layout, like...

4 minutes read.

CSS Arrow

CSS Arrow The arrow of CSS is applied to insert an array with the tooltip. It can make a tooltip as any speech bubble. Also, this arrow can be illustrated in...

4 minutes read.

CSS White Space Property

White Space in CSS The white-space CSS property describes how to show the content inside an element. This property is applied to manage a white space within an element. Values of White-space...

2 minutes read.

CSS: nth-selector

CSS nth selector can be used to match an element according to its position regardless of its parent’s type. Here, n can be any number, formula, or a keyword. These selectors...

2 minutes read.

CSS @keyframes rule

CSS @keyframes rule It describes the rule of animation that depicts the properties of CSS for the components at every state along with the timeline. We may make the properties of complex...

4 minutes read.