/

HTML / CSS / JavaScript Tutorial

CSS Property: padding-left

[this page | pdf | back links]

The CSS (CSS1) padding-left property sets the width of the left padding (space) of an element.

 

Valid property values (other than inherit and initial) are:

 

Value

Description

length

Any specified thickness as a CSS length

%

As percentage of width of containing element

 

Default Value:

0

JavaScript syntax:

e.g. object.style.paddingLeft="4px"

Inherited:

No

Animatable:

Yes

 

EXAMPLE:


HTML USED IN THIS EXAMPLE:
<!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head>
<style>
div {border: 2px solid red; width: 100px; background-color: yellow}
span {border: 2px solid green; background-color: aqua;}
.x1 {padding-left: 5px;}
</style>
</head>
<body>
1. Element with default property<br>
<div><span>1</span></div><br><br>
2. Element set using in-file HTML style<br>
<div><span class="x1">2</span></div><br><br>
3. Element set using JavaScript<br>
<div><span id="x2">3</span></div>

<script>
document.getElementById("x2").style.backgroundColor = "aqua";
document.getElementById("x2").style.paddingTop = "5px";
</script>

</body>
</html>

FUNCTION THAT MAY ASSIST IN TESTING WHETHER FEATURE IS SUPPORTED:
function isSupportedCSSPropertyPaddingLeft() {
  var x = document.createElement("DIV"); x.style.paddingLeft = "5px"; return (window.getComputedStyle(x, null).paddingLeft == "5px");
}


NAVIGATION LINKS
Contents | Prev | Next | CSS Properties


Desktop view | Switch to Mobile