Code has been added to clipboard!

Brief Guide on CSS Functions: Calc, Attr and RGBA

Reading time 2 min
Published Aug 8, 2017
Updated Oct 3, 2019

TL;DR — CSS functions are for setting property values. You can also perform mathematical calculations, add files, or set different image effects.

Use of CSS functions

CSS functions exist but are different than the functions in JavaScript or PHP.

For example, CSS calc() performs mathematical calculations when specifying the property values. With this function, it is easy to control the position of an element with a margin, set width, or height of elements.

Additionally, the CSS url() is for adding a file, and rgba() function is for setting colors.

However, not all functions apply to all CSS properties. CSS attr() is for getting values of attributes of specified elements. It works well with content property but the use with other properties is still experimental.

List of available functions

This is a reference table of popular CSS functions:

Function Description
drop-shadow() Sets a shadow effect to the input image
invert() Inverts the colors in images
translate() Positions elements to either horizontal or vertical directions
var() Add values of a custom property
url() Adds a file
rgba() Sets a color with a transparency value
blur() Sets a blur effect
opacity Sets the transparency of an element
scale() Scales elements in two-dimensional space
attr() Returns the attribute of the selected element value
calc() Lets you make calculations to complete CSS property values
linear-gradient() The image is created, representing colors a linear gradient
radial-gradient() The image is created, representing a colors gradient radiating from the gradient center
repeating-linear-gradient() The image is created, that consists of repeating gradients
repeating-radial-gradient() Automatically repeats the stops of the color in both directions. Similar to radial_gradient()

 

Tutorial
CSS3 Features
Syntax
Classes
ID Selectors
Attribute Selectors
Stylesheets
Inline
Internal
External
Box Model
Children Selectors
Pseudo Classes
Pseudo Elements
Variables
Counters
Text
Fonts
Web Fonts
Backgrounds
Background Images
Colors
Gradients
Opacity / Transparency
Shadow Effects
Transitions
Tooltip
Transform
Animations
Layout — Display
Layout — Position
Layout — Float
Layout — Clear
Layout — Horizontal & Vertical Align
Multiple Columns
Introduction
Responsive Web Design — Viewport
Responsive Web Design — Grid View
Responsive Web Design — Media Queries
Responsive Web Design — Flexbox Layout
Responsive Web Design — Images
Responsive Web Design — Videos
Borders
Margin
Padding
Width
Height
Outline
Links
Lists
Tables
Dropdown Menu
Navigation Bar
Images
Image Gallery
Border Images
Forms
Rounded Corners
Buttons
Box-Sizing
Selector Reference
Pagination Examples
Code Examples
CSS3 Browser Support Reference
Functions Reference
Speech Module Reference
Units
Web Safe Font Combinations
Cheat Sheet
:hover
@font-face
@keyframes
@media
align-content
align-items
align-self
all
animation
backface-visibility
background
background-clip
background-color
background-image
background-origin
background-position
background-size
border
border-image
border-radius
border-style
box-shadow
box-sizing
color
columns
filter
flex
flex-basis
flex-direction
flex-flow
flex-grow
flex-shrink
flex-wrap
font
font-family
font-size
font-size-adjust
font-stretch
font-style
font-weight
hanging-punctuation
justify-content
line-height
margin
offset
opacity
order
outline
overflow
padding
perspective
position
resize
tab-size
text-align
text-decoration
text-emphasis
text-transform
text-shadow
transform
transition-property
translate
vertical-align
word-break
word-wrap
z-index