100% Practical, Personalized, Classroom Training and Assured Job Book Free Demo Now
App Development
Digital Marketing
Other
Programming Courses
Professional COurses
This CSS tutorial, whether you’re a student or a professional is a valuable resource to enhance the visual appeal of your websites or personal blogs. Here, you will learn CSS from basic to advanced concepts, such as properties, selectors, functions, media queries, and more.
CSS is used to enhance the visual presentation of web pages. Without the use of CSS, a web page will appear visually unappealing.
Cascading Style Sheets, fondly referred to as CSS, is a simply designed language intended to simplify the process of making web pages presentable. CSS allows you to apply styles to web pages. More importantly, CSS enables you to do this independently of the HTML that makes up each web page. It describes how a webpage should look: it prescribes colours, fonts, spacing, and much more. In short, you can make your website look however you want. CSS lets developers and designers define how it behaves, including how elements are positioned in the browser.
While HTML uses tags, CSS uses rulesets. CSS is easy to learn and understand, but it provides powerful control over the presentation of an HTML document.
CSS versions release years:
CSS Syntax:
CSS comprises style rules that are interpreted by the browser and then applied to the corresponding elements in your document. A style rule set consists of a selector and declaration block.
Selector -- h1
Declaration -- {color:blue;font size:12px;}
For example :
selector { Â Â Â Â property 1: value 1 ; Â Â Â Â property 2: value 2 ; } |
CSS declaration always ends with a semicolon, and declaration blocks are surrounded by curly braces.
Here is a more specific example:Â In the following example all p elements will be centre-aligned, with a blue text colour:
p { Â Â Â Â color : blue ; Â Â Â Â text-align : center ; } |
Let’s see how our page looks with & without CSS :
Before CSS:Â In this example, we have not added any CSS.
Â
Â
Â
<!DOCTYPE html> < html > < head > Â Â Â Â < title >Example</ title > </ head > < body > Â Â Â Â < main > Â Â Â Â Â Â Â < h1 >HTML Page</ h1 > Â Â Â Â Â Â Â < p >This is a basic web page.</ p > Â Â Â Â </ main > </ body > </ html > |
Output:
After CSS:Â In this example, we added some CSS styling inside the HTML code only to show how CSS makes a dull HTML page look beautiful.
<!DOCTYPE html> < html > Â < head > Â Â Â Â < title >Example</ title > Â Â Â Â < style > Â Â Â Â Â Â Â Â main { Â Â Â Â Â Â Â Â Â Â Â Â width: 600px; Â Â Â Â Â Â Â Â Â Â Â Â height: 200px; Â Â Â Â Â Â Â Â Â Â Â Â padding: 10px; Â Â Â Â Â Â Â Â Â Â Â Â background: beige; Â Â Â Â Â Â Â Â } Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â h1 { Â Â Â Â Â Â Â Â Â Â Â Â color: olivedrab; Â Â Â Â Â Â Â Â Â Â Â Â border-bottom: 1px dotted darkgreen; Â Â Â Â Â Â Â Â } Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â p { Â Â Â Â Â Â Â Â Â Â Â Â font-family: sans-serif; Â Â Â Â Â Â Â Â Â Â Â Â color: orange; Â Â Â Â Â Â Â Â } Â Â Â Â </ style > </ head > Â < body > Â Â Â Â < main > Â Â Â Â Â Â Â Â < h1 >My first Page</ h1 > Â Â Â Â Â Â Â Â < p >This is a basic web page.</ p > Â Â Â Â </ main > </ body > Â </ html > |
Output:
A CSS Syntax rule consists of a selector, property, and its value. The selector points to the HTML element where the CSS style is to be applied. The CSS property is separated by semicolons. It is a combination of the selector name followed by the property: value pair that is defined for the specific selector.Â
Syntax:
selector { Property: value; }
CSS Color property is used to set the color of HTML elements. This property is used to set font color, background color, etc. The color of an element can be defined in the following ways:
Built-In Color:Â These are a set of predefined colors which are used by its name. For example: red, blue, green etc.
Syntax:
h1 { color: color-name; }
In this article, we will learn about the CSS Margin & Padding properties of the Box Model & understand their implementation through the example.Â
CSS Margins:Â CSS margins are used to create space around the element. We can set the different sizes of margins for individual sides(top, right, bottom, left).
Margin properties can have the following values:
Syntax:
body {
margin: value;
}
The margin property is a shorthand property having the following individual margin properties:
We will discuss all 4 properties sequentially.
1. If the margin property has 4 values:Â
margin: 40px 100px 120px 80px;
2. If the margin property has 3 values:Â
margin: 40px 100px 120px;Â
3. If the margin property has 2 values:
margin: 40px 100px;Â
4.If the margin property has 1 value:Â
margin: 40px;Â
CSS Animation:Â CSS Animations is a technique to change the appearance and behavior of various elements in web pages. It is used to control the elements by changing their motions or display. It has two parts, one contains the CSS properties which describe the animation of the elements and the other contains certain keyframes which indicate the animation properties of the element and the specific time intervals at which those have to occur.Â
Keyframes are the foundations with the help of which CSS Animations work. They define the display of the animation at the respective stages of its whole duration. For example: In the first example code, the paragraph changes its color with time. At 0% completion, it is red, at 50% completion it is of orange color and at full completion i.e. at 100%, it is brown.Â
/*property-name*/: /*value*/;
There are certain animation properties given below:
The CSS background properties are used to define the background effects for elements. There are lots of properties to design the background.Â
CSS background properties are as follows:Â
Background color Property: This property specifies the background color of an element. A color name can also be given as: “greenâ€, a HEX value as “#5570f0â€, an RGB value as “rgb(25, 255, 2)â€.Â
Syntax:
body { background-color:color name }
Background Image Property:Â This property specifies an image to use as the background of an element. By default, the image is repeated so it covers the entire element.Â
Syntax:Â
body { background-image : link; }
Background repeat Property:Â By default the background image property repeats the image both horizontally and vertically.Â
Syntax:Â To repeat an image horizontally
body { background-image:link; background-repeat: repeat:x; }
Background-attachment Property:Â This property is used to fix the background ground image. The image will not scroll with the page.Â
Syntax:Â
body { background-attachment: fixed; }
Background-position Property:Â This property is used to set the image to a particular position.Â
Syntax :Â
body { background-repeat:no repeat; background-position:left top; }
Â
The position property in CSS tells about the method of positioning for an element or an HTML entity and the positioning of an element can be done using the top, right, bottom, and left properties. These specify the distance of an HTML element from the edge of the viewport.Â
There are five different types of position properties available in CSS:
CSS Specificity of the Selectors can be determined when more than one set of CSS rules applies to the same element, the browser will have to decide which specific set will be applied to the element. This set of rules that the browser follows is collectively called Specificity.
Inline CSS is a method of applying CSS styling directly within HTML elements using the “style†attribute. It has the highest specificity and will override all other selectors, including External stylesheets and Internal CSS.
Internal stylesheets are a method for defining CSS styles within an HTML document’s <style> element. This styling can be used when we want to directly implement the styles within an HTML Document. The specificity of this styling depends on the CSS Selector used with the Element. For instance, if an id is used then it has the highest specificity, in comparison to the External stylesheet. For this, internal CSS will override rules defined in an external stylesheet.
External CSS is used to style multiple HTML pages with a single style sheet. External CSS contains a separate CSS file with a .css extension. This style can be linked via the <link> tag in the HTML document. The specificity of this styling also depends on the CSS Selector used with the Element.Â
Error: Contact form not found.