×

CSS Functions

CSS functions are used for different CSS properties. Every front-end developer should have knowledge of all CSS functions. It makes the coding easier.

FunctionsExplanation
attr().It returns the value of an attribute of the selected element, which is quite significant.
calc().Allows you to specifically perform calculations to determine CSS property values, kind of contrary to popular belief. Calculate any mathematical functions.
conic - gradient().It creates a conic gradient subtly.
counter().Returns the very current value of the named counter in a major way.
cubic - bezier().Explains a cubic Bezier curve, kind of contrary to popular belief.
hsl().Explains colors using the Hue-Saturation-Lightness model (HSL) subtly. This function describes the level of colors by using hsl.
hsla().Explains colors using the Hue-Saturation-Lightness-Alpha model (HSLA) in a major way.
linear - gradient().This function works as an inbuilt function in CSS which is utilized to set the linear gradient as background picture.
max().Uses the largest value, from a comma-separated list of values, as the property value. Set the max of nos. Given.
min().This function works in css is utilized to extract the mini value from a bunch of comma-separated values. 
repeating - conic - gradient().Repeats a conic gradient, which generally is quite significant.
repeating - linear - gradient().Repeats a linear gradient, definitely contrary to popular belief. 
repeating - radial - gradient().Subtly repeats a radial gradient.  
rgb().Explains colors using the Red-Green-Blue model (RGB) subtly. Describes the level of color.
rgba().Explains colors using the Red-Green-Blue-Alpha model (RGBA). Describes the levels of color.
var().Inserts the value of a custom property, which is fairly significant.
url()Function is used to set list-style, image, cursor, mask, mask-image, background-image, content, list-style-image.
blur()Blur effect is applied by this function.
brightness()The brightness is adjust by this function.
opacity()Opacity of the element is set .
not()Apply the style to image (img) element not having .no-p class.

Some functions for the most part are described/explained using small code(syntax) are as follows :

background: url(“image.png/image.jpg”)

height: calc(90%-50px)

      -    var( <custom-property-name> , <declaration-value>? )

      -    color: rgb(0,0,0)

color: rgba(0,0,0,1)

color: hsl(0,0,0)

.body{
          filter: blur(100px);
              }

.h2{
       filter: brightness(40%);
    }

img {
      filter: opacity(40%);
   }

img:not(.no-p){
           padding: 0;  }

Some examples with its code and output:

1. calc() function-

            code is as follows:

<!DOCTYPE html>
           <html>
           <head>
           <style>
             #div1 
              { position: absolute;
                  left: 45px;
                  width: calc(50% - 50px);
                  border: 1px solid black;
                  background-color: lightgray;
                  padding: 4px;
                  text-align: center;
               }
               </style>
               </head>                       
    <body>
      <h1> The calc() function  in CSS </h1>
      <p> This is the short paragraph which creates div , <br>
             with a 40px gap between both sides of 
             the div and edge of window: </p> 
      <div id=”div1”>write something text here..</div>
      </body>
      </html>

Output 1 for the above calc() code is:

CSS Functions

2. rgb() function-

code is as follows

<!DOCTYPE html>
                 <html>
                 <head>  
<style>
#p1 { background-color: rgb(128 , 0 , 128) ; } 
#p2 { background-color: rgb (255 , 255, 0) ; }
#p3 { background-color: rgb (255, 0 , 255 ) ; }
#p4 { background-color: rgb (192,192 ,192 ) ; }
#p5 { background-color: rgb (0 , 255, 0) ; }
#p6 { background-color: rgb (0 , 128, 128) ; }
#p7 { background-color: rgb ( 255, 127 , 80  ) ; }
</style>
</head>
<body>
<h1>The rgb() Function in CSS </h1>
<p> Different rgb colors : </p> 
< p id=”p1”> Purple </p>
< p id=”p2”> Yellow </p>
< p id=”p3”> Blue  </p>
< p id=”p4”> Silver </p>
< p id=”p5”> Lime </p>
< p id=”p6”> Teal </p>
< p id=”p7”> Coral </p>
</body>
</html>

Output for the above rgb() code is:

CSS Functions

3. rgba() function

code is as follows :

<!DOCTYPE html>
<html>
<head>  
<style>
#p1 { background-color: rgba(198, 0 , 198,0.3 ) ; } 
#p2 { background-color: rgba(20, 214, 20, 0.836); }
#p3 { background-color: rgba(0,0,255,0.3 ); }
#p4 { background-color: rgba(192,192,192,0.3 ) ; }
#p5 { background-color: rgba(255, 255, 0, 0.884) ; }
#p6 { background-color: rgba(240, 84, 12, 0.795) ; }
#p7 { background-color: rgba(255, 0, 0, 0.473) ; }
</style>
</head>
<body>
<h1>The rgb() Function in CSS </h1>
<p> Different rgb colors : </p> 
<p id="p1"> Purple </p>
<p id="p2"> Green </p>
<p id="p3"> Blue </p>
<p id="p4"> Light blue </p>
<p id="p5"> Yellow </p>
<p id="p6"> Orange </p>
<p id="p7"> Pink </p>




</body>
</html>

Output for the above rgba() code is:

CSS Functions

4. blur() function

code is as follows :

<!DOCTYPE html> 
<html> 
<head> 
    <title>The blur() Function in CSS </title> 
 <style>
        h1 {
            color: pink ;
             }
  body {
            text-align:center;
        }
        .blur_effect {
            filter: blur(4px);
        }
</style>
</head> 
<body> 
    <h1>Flower photograph </h1> 
    <h2>CSS blur() function</h2>
   <img class="blur_effect" src = "flower.png"
        alt="Flower image"> 
</body> 
</html>

Output for the above blur() code is:

CSS Functions

Related Topics

CSS Pseudo-elements

Pseudo-elements The pseudo-classes in CSS can be represented as any keyword which is connected to the selector that represents any selected element’s unique state. On the other hand, pseudo-elements can be...

6 minutes read.

CSS Text-Overflow

Introduction: The text-overflow property of CSS is used to format the text which is overflowing the boundaries of the container. This property helps user to clip the text, to display the...

5 minutes read.

Radial-gradient() CSS function

Radial-gradient() CSS function It defines a CSS in-built function, which produces a smooth transition among multiple colors. It is used to set any radial-gradient that is same as a background-image. This...

4 minutes read.

CSS Superscript and Subscript

Superscript and Subscript To specify the superscript and the subscript text, HTML provides us two tags that are <sup> and <sub>. The superscript content looks in the shorter font and half...

2 minutes read.

How to edit CSS in WordPress

Developing a new website or blog is a difficult undertaking. We want to create something that the consumers will adore, but we might not want the setting to take months and...

7 minutes read.

CSS Comments

CSS Comments: Generally, comments in CSS are used to describe our code. Further, it will provide support to many users who are concerned with the code. Somewhat, these are ignored...

2 minutes read.

CSS User Interface

Introduction User Interface can be defined as series of visual elements like screens, buttons, forms that help the user interact with the software application or hardware device. CSS User Interface allows the...

6 minutes read.

CSS Pseudo-class

Pseudo-class The pseudo-class may be depicted as the keyword which can be mixed to any selector that specifies the elected element’s unique state. It can be included to a selector to...

6 minutes read.

How to change the font in CSS

How to change the font in CSS? Professionals can't deny typefaces — how users organize and style text — if we want to completely customize the website's design. One may wish...

4 minutes read.

CSS Radio Button

Radio Button A radio button has been defined as an element of HTML. It can support us to take any input from the user. But it is challenging to design a...

4 minutes read.

CSS Specificity

CSS Specificity: If one or more conflicting rules of CSS express a similar element, a browser will pursue a few rules to examine the specific one. Specificity can be specified...

3 minutes read.

CSS calc()

CSS calc(): The CSS calc() function is a CSS function of inbuilt type, which permits us to implement calculations. It is used for calculating the angle, integer frequency, number, time,...

3 minutes read.

How to center a button in CSS

How to center a button in CSS? In the tutorial, we will learn how to center a button in CSS. CSS (Cascading Style Sheets) gives an HTML web page the greatest possible...

4 minutes read.

CSS Background-clip

CSS Background-clip: The background-clip property describes the background’s painting area. It limits an area where the image or color of the background appears by using any clipping box. Everything will...

2 minutes read.

Is CSS a programming language?

 A programming language is a set of grammatical rules and a vocabulary for commanding a machine to accomplish specified tasks. High-level languages like BASIC, C, C++, COBOL, Java, FORTRAN, Ada...

4 minutes read.

CSS Masking

CSS Masking The CSS mask property is applied to hide a component with the use of the masking or clipping an image at any specific point. The masking depicts the use...

3 minutes read.

CSS Letter-spacing

CSS Letter-spacing: Letter-spacing attribute is applied to manage the space among all letters within the block or element of the text. This property sets the behavior of the spacing between...

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.

CSS Counters

CSS Counters: The CSS counter property is similar to the variables. CSS counters are controlled via CSS, and its values are incremented via rules of CSS to record how much...

4 minutes read.

How to center a table in CSS

The table is used to store and arrange the data in tabular format. The data here can be of any form like text, image, links, etc. The table is made...

3 minutes read.