The calc() function is an inbuilt function in CSS which is used to perform calculations based on CSS property.
Syntax:
calc( Expression )
Parameters: This function accepts single parameter Expression which is mandatory. This parameter contains mathematical expression which need to implement. The operators used by this parameters are: +, -, *, /
Below program illustrates the calc() function in CSS:
Program:
<!DOCTYPE html> <html> <head> <title>calc function</title> <style> .geeks { position: absolute; left: 50px; width: calc(100% - 20%); height:calc(500px - 300px); background-color: green; padding-top:30px; text-align: center; } .gfg { font-size:40px; font-weight:bold; color:white } h1 { color:white; } </style> </head> <body> <div class = "geeks"> <div class = "gfg">GeeksforGeeks</div> <h1>The calc() Function</h1> </div> </body> </html> |
Output:

Recommended Posts:
- SASS Variable in CSS calc() function
- How to Set Calc Viewport Units Workaround in CSS ?
- How to override the CSS properties of a class using another CSS class ?
- Difference between bootstrap.css and bootstrap-theme.css
- CSS | rgb() Function
- CSS | rgba() Function
- CSS | hsla() Function
- CSS | hsl() Function
- CSS | cubic-bezier() Function
- CSS | attr() Function
- CSS | linear-gradient() Function
- CSS | radial-gradient() Function
- CSS | repeating-radial-gradient() Function
- CSS | repeating-linear-gradient() Function
- CSS | animation-timing-function Property
- CSS | var() Function
- How to remove style added with .css() function using JavaScript?
- CSS | brightness() Function
- CSS | blur() Function
- CSS | contrast() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


