Search the site:

Copyright 2010 - 2024 @ DevriX - All rights reserved.

CSS Shorthand vs Longhand Properties

CSS Shorthand vs Longhand Properties

CSS shorthand vs longhand – one of them is concise and another one is precise. One came to presence out of the need for curtness, while the alternate stands firm to protect clarity. In any case, they have their own purposes, advantages, and even disadvantages (in some cases).

CSS Shorthand vs Longhand Properties

CSS Shorthand vs Longhand Properties

A fabulous approach to improve and streamline your CSS is to exploit the wide range of shorthand properties accessible to you. Working with a great deal of CSS, you inevitably retain these diverse alternate ways. Here we will demonstrate to you the shorthand guidelines for the accompanying properties:

  • Background Properties
  • Textual Style Properties
  • Transition Properties
  • List Properties
  • Outline and Border Properties

These are the main 5 on our rundown of most frequently utilized shorthand properties. There are also others, even in CSS3.

Background Properties

This exceptionally helpful property permits you to consolidate a few qualities into one: the background property. It is similar to textual style, utilizes the default values when they are not available in the announcement.

CSS Longhand


background-color: #456;
background-image: url("backdrop.gif");
background-repeat: repeat-y;
background-attachment: fixed;
background-position: 50% 50%;

CSS Shorthand


background: #456 url("backdrop.gif") repeat-y fixed 50% 50%;

Either the background shading or the image must be characterized. The default qualities are recorded underneath:


background-color: transparent;
background-image: none;
background-repeat: repeat;
background-attachment: scroll;
background-position: 0% 0%;

Maybe the most well-known mistakes individuals make when utilizing the background property is exchanging the position values. Luckily, most originators are more acquainted with the shorthand documentation than the individual properties themselves.

Textual Style Properties

Textual styles include various individual properties. You can spare a considerable amount of space utilizing shorthand documentation, however be mindful to incorporate in any event text-size and text-family in a specific order.

CSS Longhand


font-style: italic;
font-variant: small-caps;
font-weight: 500;
font-size: 1em;
line-height: 24px;
font-family: arial, sans-serif;

The majority of alternate values that were overlooked are acquired, so in the event that you haven’t set a property somewhere else in your CSS, they will be set to the default esteem. As should be obvious, a solitary line of code is utilized to supplant a whole block.

CSS Shorthand


font: italic small-caps 500 1em/24px arial, serif;

Transition Property

Unadulterated CSS transitions are the most smoking things since flapjacks, so despite the fact that just WebKit-based programs, for example, Safari comprehend the transition’s property, it is conceivable to get transitions working in Firefox, Chrome, and Opera with only a couple of extra lines of CSS. Here are every one of the 4 of the move properties alongside their default values:

CSS Longhand


transition-property: all;
transition-duration: 0s;
transition-timing-function: ease;
transition-delay: 0s;

CSS Shorthand


transition: opacity 3s ease-in-out 1s;

We require a couple of extra guidelines to get transitions working in all non-IE programs. The extra assertions quiet the tastefulness of the transitions shorthand, yet it lives up to expectations.

Vendor-specific prefixes


-webkit-transition: opacity 3s ease 1s;
-moz-transition: opacity 3s ease 1s;
-o-transition: opacity 3s ease 1s;
transition: opacity 3s ease 1s;

List Property

There are only 3 list style properties. They are image, type and position. It is possible to combine them into a single line.

CSS Longhand


list-style-type: disc;
list-style-position: outside;
list-style-image: url("bg.png");

CSS Shorthand


list-style: disc outside url("bg.png");

Outline and Border Properties

You can easily simplify style, width and color.

CSS Longhand


border-width: 2px;
border-style: solid;
border-color: #000;

CSS Shorthand


border: 2px solid #000;

CSS Shorthand vs Longhand Properties: Which Should You Use?

Ultimately, which should you use CSS Shorthand or Longhand properties? Well, you can try shorthand or longhand according to your needs.