/

HTML / CSS / JavaScript Tutorial

CSS Property: text-align-last

[this page | pdf | back links]

The CSS (CSS3) text-align-last property indicates how the last line of text in an element should be aligned.

 

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

 

Value

Description

auto

(default value). Last line is aligned left

center

Last line of text is centred

end

Last line is aligned to end of line (right if direction is left-to-right, left if direction is right-to-left)

justify

Justifies last line of text, i.e. stretches lines to encompass whole width (rarely how text is formatted in practice)

left

Aligns last line of text to left

start

Last line is aligned to start of line (left if direction is left-to-right, right if direction is right-to-left)

right

Aligns last line of text to right

 

Default Value:

auto

JavaScript syntax:

e.g. object.style.textAlignLast="right"

Inherited:

Yes

Animatable:

No

 

EXAMPLE:


HTML USED IN THIS EXAMPLE:
<!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head>
<style>
div {width: 300px; border: 1px solid black;}
div.x1 {text-align: justify; text-align-last: right}
</style>
</head>
<body>
Note: not all browsers seem to support this property effectively for some element types<br><br>
1. Element with default property<br>
<div>Some text that is longer than one line, so has a last line that may be formatted differently to remainder</div><br><br>
2. Element set using in-file HTML style
<div class="x1">Some text that is longer than one line, so has a last line that may be formatted differently to remainder</div><br><br>
3. Element set using JavaScript
<div id="x2">Some text that is longer than one line, so has a last line that may be formatted differently to remainder</div>

<script>
document.getElementById("x2").style.columnSpan = "all";
document.getElementById("x2").style.textAlign = "justify";
document.getElementById("x2").style.textAlignLast = "right";
</script>

</body>
</html>

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


NAVIGATION LINKS
Contents | Prev | Next | CSS Properties


Desktop view | Switch to Mobile