PERSPECTIVE-ORIGIN
The perspective-origin property establishes the origin for the perspective property.
SYNTAX
CSS
perspective-origin: value;
JS
object.style.perspectiveOrigin = "value";
VALUES
<'perspective-origin'> = <position>
<position> = [ [ left | center | right ] || [ top | center | bottom ] | [ left | center | right | <length-percentage> ] [ top | center | bottom | <length-percentage> ]? | [ [ left | right ] <length-percentage> ] && [ [ top | bottom ] <length-percentage> ] ]
<length-percentage> = [ <length> | <percentage> ]
<length>
Specifies the length using a number followed by a unit of measurement.
<percentage>
Specifies the percentage using a number followed by a percent sign (%).
INITIAL
EXAMPLES
BOTTOM
CENTER
<!doctype html>
<html>
<head>
<style>
.cube {
height: 100px;
margin: 100px;
perspective: 100px;
perspective-origin: center;
transform-style: preserve-3d;
width: 100px;
}
.face {
color: white;
font-family: sans-serif;
font-size: 25px;
height: 100px;
line-height: 100px;
position: absolute;
text-align: center;
width: 100px;
}
.left {
background-color: rgba(255, 0, 0, 0.5);
transform: rotateY(-90deg) translateZ(50px);
}
.right {
background-color: rgba(255, 255, 0, 0.5);
transform: rotateY(90deg) translateZ(50px);
}
.bottom {
background-color: rgba(0, 255, 0, 0.5);
transform: rotateX(-90deg) translateZ(50px);
}
.top {
background-color: rgba(0, 255, 255, 0.5);
transform: rotateX(90deg) translateZ(50px);
}
.front {
background-color: rgba(0, 0, 255, 0.5);
transform: translateZ(50px);
}
.back {
background-color: rgba(255, 0, 255, 0.5);
transform: rotateY(180deg) translateZ(50px);
}
</style>
</head>
<body>
<p>center</p>
<div class="cube">
<div class="face left">left</div>
<div class="face right">right</div>
<div class="face bottom">bottom</div>
<div class="face top">top</div>
<div class="face front">front</div>
<div class="face back">back</div>
</div>
</body>
</html>
LEFT
<!doctype html>
<html>
<head>
<style>
.cube {
height: 100px;
margin: 100px;
perspective: 100px;
perspective-origin: left;
transform-style: preserve-3d;
width: 100px;
}
.face {
color: white;
font-family: sans-serif;
font-size: 25px;
height: 100px;
line-height: 100px;
position: absolute;
text-align: center;
width: 100px;
}
.left {
background-color: rgba(255, 0, 0, 0.5);
transform: rotateY(-90deg) translateZ(50px);
}
.right {
background-color: rgba(255, 255, 0, 0.5);
transform: rotateY(90deg) translateZ(50px);
}
.bottom {
background-color: rgba(0, 255, 0, 0.5);
transform: rotateX(-90deg) translateZ(50px);
}
.top {
background-color: rgba(0, 255, 255, 0.5);
transform: rotateX(90deg) translateZ(50px);
}
.front {
background-color: rgba(0, 0, 255, 0.5);
transform: translateZ(50px);
}
.back {
background-color: rgba(255, 0, 255, 0.5);
transform: rotateY(180deg) translateZ(50px);
}
</style>
</head>
<body>
<p>left</p>
<div class="cube">
<div class="face left">left</div>
<div class="face right">right</div>
<div class="face bottom">bottom</div>
<div class="face top">top</div>
<div class="face front">front</div>
<div class="face back">back</div>
</div>
</body>
</html>
LENGTH
<!doctype html>
<html>
<head>
<style>
.cube {
height: 100px;
margin: 100px;
perspective: 100px;
perspective-origin: 100px 100px;
transform-style: preserve-3d;
width: 100px;
}
.face {
color: white;
font-family: sans-serif;
font-size: 25px;
height: 100px;
line-height: 100px;
position: absolute;
text-align: center;
width: 100px;
}
.left {
background-color: rgba(255, 0, 0, 0.5);
transform: rotateY(-90deg) translateZ(50px);
}
.right {
background-color: rgba(255, 255, 0, 0.5);
transform: rotateY(90deg) translateZ(50px);
}
.bottom {
background-color: rgba(0, 255, 0, 0.5);
transform: rotateX(-90deg) translateZ(50px);
}
.top {
background-color: rgba(0, 255, 255, 0.5);
transform: rotateX(90deg) translateZ(50px);
}
.front {
background-color: rgba(0, 0, 255, 0.5);
transform: translateZ(50px);
}
.back {
background-color: rgba(255, 0, 255, 0.5);
transform: rotateY(180deg) translateZ(50px);
}
</style>
</head>
<body>
<p>length</p>
<div class="cube">
<div class="face left">left</div>
<div class="face right">right</div>
<div class="face bottom">bottom</div>
<div class="face top">top</div>
<div class="face front">front</div>
<div class="face back">back</div>
</div>
</body>
</html>
PERCENTAGE
<!doctype html>
<html>
<head>
<style>
.cube {
height: 100px;
margin: 100px;
perspective: 100px;
perspective-origin: 100% 100%;
transform-style: preserve-3d;
width: 100px;
}
.face {
color: white;
font-family: sans-serif;
font-size: 25px;
height: 100px;
line-height: 100px;
position: absolute;
text-align: center;
width: 100px;
}
.left {
background-color: rgba(255, 0, 0, 0.5);
transform: rotateY(-90deg) translateZ(50px);
}
.right {
background-color: rgba(255, 255, 0, 0.5);
transform: rotateY(90deg) translateZ(50px);
}
.bottom {
background-color: rgba(0, 255, 0, 0.5);
transform: rotateX(-90deg) translateZ(50px);
}
.top {
background-color: rgba(0, 255, 255, 0.5);
transform: rotateX(90deg) translateZ(50px);
}
.front {
background-color: rgba(0, 0, 255, 0.5);
transform: translateZ(50px);
}
.back {
background-color: rgba(255, 0, 255, 0.5);
transform: rotateY(180deg) translateZ(50px);
}
</style>
</head>
<body>
<p>percentage</p>
<div class="cube">
<div class="face left">left</div>
<div class="face right">right</div>
<div class="face bottom">bottom</div>
<div class="face top">top</div>
<div class="face front">front</div>
<div class="face back">back</div>
</div>
</body>
</html>
RIGHT
<!doctype html>
<html>
<head>
<style>
.cube {
height: 100px;
margin: 100px;
perspective: 100px;
perspective-origin: right;
transform-style: preserve-3d;
width: 100px;
}
.face {
color: white;
font-family: sans-serif;
font-size: 25px;
height: 100px;
line-height: 100px;
position: absolute;
text-align: center;
width: 100px;
}
.left {
background-color: rgba(255, 0, 0, 0.5);
transform: rotateY(-90deg) translateZ(50px);
}
.right {
background-color: rgba(255, 255, 0, 0.5);
transform: rotateY(90deg) translateZ(50px);
}
.bottom {
background-color: rgba(0, 255, 0, 0.5);
transform: rotateX(-90deg) translateZ(50px);
}
.top {
background-color: rgba(0, 255, 255, 0.5);
transform: rotateX(90deg) translateZ(50px);
}
.front {
background-color: rgba(0, 0, 255, 0.5);
transform: translateZ(50px);
}
.back {
background-color: rgba(255, 0, 255, 0.5);
transform: rotateY(180deg) translateZ(50px);
}
</style>
</head>
<body>
<p>right</p>
<div class="cube">
<div class="face left">left</div>
<div class="face right">right</div>
<div class="face bottom">bottom</div>
<div class="face top">top</div>
<div class="face front">front</div>
<div class="face back">back</div>
</div>
</body>
</html>
TOP
<!doctype html>
<html>
<head>
<style>
.cube {
height: 100px;
margin: 100px;
perspective: 100px;
perspective-origin: top;
transform-style: preserve-3d;
width: 100px;
}
.face {
color: white;
font-family: sans-serif;
font-size: 25px;
height: 100px;
line-height: 100px;
position: absolute;
text-align: center;
width: 100px;
}
.left {
background-color: rgba(255, 0, 0, 0.5);
transform: rotateY(-90deg) translateZ(50px);
}
.right {
background-color: rgba(255, 255, 0, 0.5);
transform: rotateY(90deg) translateZ(50px);
}
.bottom {
background-color: rgba(0, 255, 0, 0.5);
transform: rotateX(-90deg) translateZ(50px);
}
.top {
background-color: rgba(0, 255, 255, 0.5);
transform: rotateX(90deg) translateZ(50px);
}
.front {
background-color: rgba(0, 0, 255, 0.5);
transform: translateZ(50px);
}
.back {
background-color: rgba(255, 0, 255, 0.5);
transform: rotateY(180deg) translateZ(50px);
}
</style>
</head>
<body>
<p>top</p>
<div class="cube">
<div class="face left">left</div>
<div class="face right">right</div>
<div class="face bottom">bottom</div>
<div class="face top">top</div>
<div class="face front">front</div>
<div class="face back">back</div>
</div>
</body>
</html>
JS
<!doctype html>
<html>
<head>
<style>
.cube {
height: 100px;
margin: 100px;
perspective: 100px;
transform-style: preserve-3d;
width: 100px;
}
.face {
color: white;
font-family: sans-serif;
font-size: 25px;
height: 100px;
line-height: 100px;
position: absolute;
text-align: center;
width: 100px;
}
.left {
background-color: rgba(255, 0, 0, 0.5);
transform: rotateY(-90deg) translateZ(50px);
}
.right {
background-color: rgba(255, 255, 0, 0.5);
transform: rotateY(90deg) translateZ(50px);
}
.bottom {
background-color: rgba(0, 255, 0, 0.5);
transform: rotateX(-90deg) translateZ(50px);
}
.top {
background-color: rgba(0, 255, 255, 0.5);
transform: rotateX(90deg) translateZ(50px);
}
.front {
background-color: rgba(0, 0, 255, 0.5);
transform: translateZ(50px);
}
.back {
background-color: rgba(255, 0, 255, 0.5);
transform: rotateY(180deg) translateZ(50px);
}
</style>
<script>
function mouseover(value) {
document.getElementsByClassName("cube")[0].style.perspectiveOrigin = value;
}
</script>
</head>
<body>
<input onmouseover="mouseover(value)" type="button" value="bottom">
<input onmouseover="mouseover(value)" type="button" value="center">
<input onmouseover="mouseover(value)" type="button" value="left">
<button onmouseover="mouseover(value)" value="100px 100px">length</button>
<button onmouseover="mouseover(value)" value="100% 100%">percentage</button>
<input onmouseover="mouseover(value)" type="button" value="right">
<input onmouseover="mouseover(value)" type="button" value="top">
<p>perspective-origin</p>
<div class="cube">
<div class="face left">left</div>
<div class="face right">right</div>
<div class="face bottom">bottom</div>
<div class="face top">top</div>
<div class="face front">front</div>
<div class="face back">back</div>
</div>
</body>
</html>
LINKS
INTERNAL
EXTERNAL