NEW POSTS
latest
CSS
CSS

Pages

Contact Form

Name

Email *

Message *

Latest Articles

Base Tag in HTML

HTML <base> Tag

The HTML <base> tag defines a default URL and target for relative links in an HTML document. It helps browsers determine where relative URLs should point and where linked pages should open.

For example, if a website contains several links to pages, images, stylesheets, or other resources, you can use the <base> tag to define a common starting URL. The browser will then use that URL to resolve relative paths throughout the document.

The <base> tag must be placed inside the <head> section of an HTML document. A document can contain only one <base> element.

Syntax of the HTML <base> Tag

The basic syntax is:

<base href="URL" target="target">

The <base> tag supports two attributes:

  • href: Specifies the base URL for relative URLs in the document.
  • target: Defines the default browsing context where links and form submissions should open.

You can use either attribute or both together.

HTML <base> Tag Example

Consider the following example:

<!DOCTYPE html>
<html>
<head>
    <title>HTML Base Tag Example</title>
    <base href="https://www.w3schools.com/" target="_blank">
</head>
<body>

    <h2>HTML Base Tag</h2>

    <a href="tags/tag_base.asp">HTML Base Tag</a>

    <img src="images/stickman.gif" width="24" height="39" alt="Stickman">

</body>
</html>

In this example, the <base> element specifies https://www.w3schools.com/ as the default URL and _blank as the default target.

As a result:

  • The link tags/tag_base.asp points to https://www.w3schools.com/tags/tag_base.asp.
  • The image path images/stickman.gif points to https://www.w3schools.com/images/stickman.gif.
  • The link opens in a new browser tab because its target is _blank.

Without the <base> element, the browser would resolve these relative URLs using the current document's URL.

The href Attribute

The href attribute specifies the base URL that the browser uses to resolve relative URLs.

For example:

<head>
    <base href="https://www.w3schools.com/">
</head>
<body>

    <a href="tags/tag_base.asp">HTML Tutorial</a>
    <a href="css/default.asp">CSS Tutorial</a>

</body>

The browser resolves the relative paths using the base URL:

  • tags/tag_base.asp becomes https://www.w3schools.com/tags/tag_base.asp.
  • css/default.asp becomes https://www.w3schools.com/css/default.asp.

This is useful when a page contains several relative URLs that share the same starting location.

The href attribute can also contain a relative URL. In that case, the browser resolves it against the document's original URL.

The target Attribute

The target attribute specifies where a browser should open a linked resource by default.

For example:

<head>
    <base target="_blank">
</head>
<body>

    <a href="https://www.w3schools.com/">Visit W3Schools</a>
    <a href="https://www.wikipedia.org/">Visit Wikipedia</a>

</body>

Both links open in new browser tabs because the base element sets _blank as the default target.

The main target values are:

Target Description
_self Opens the linked resource in the current browsing context. This is the default behavior.
_blank Opens the linked resource in a new browsing context, usually a new tab.
_parent Opens the resource in the parent frame. If there is no parent frame, it behaves like _self.
_top Opens the resource in the full browser window, outside any frames.

You can also assign a custom browsing context name instead of using these predefined values.

Note: An individual link can have its own target attribute. When that happens, its specified target takes priority over the default target set by <base>.

Important Rules for Using the <base> Tag

There are several rules to remember when working with the HTML <base> element.

  1. Use only one base element: An HTML document should contain a maximum of one <base> element.
  2. Place it inside the head section: The element must appear within the document's <head>.
  3. Specify at least one attribute: The element must have either href, target, or both.
  4. Place it before URL-based elements: When the href or target attribute is specified, the <base> element must appear before other elements that use URL attributes, such as <link>.
  5. It is a void element: The <base> tag does not have a closing tag or any content between opening and closing tags.
  6. Explicit targets take priority: A link with its own target attribute uses that value instead of the default target defined by <base>.

Although browsers ignore additional <base> elements, you should not include more than one in a document.

How Does the <base> Tag Affect Internal Page Links?

One important detail about the <base> tag is that it also affects links to sections within the same page.

For example:

<head>
    <base href="https://www.w3schools.com/">
</head>
<body>

    <a href="#contact">Go to Contact Section</a>

    <h2 id="contact">Contact Us</h2>

</body>

You might expect the link to jump directly to the Contact Us section. However, the browser resolves the link against the base URL.

In this example, the resulting URL is:

https://www.w3schools.com/#contact

Therefore, the browser may navigate to that URL instead of simply jumping to the section in the current document.

If you use the <base> element, pay special attention to internal navigation links.

Does the <base> Tag Support Global Attributes?

Yes. The <base> element supports the standard HTML global attributes.

However, it does not support event handler attributes because it is a metadata element rather than an interactive element.

The <base> element also has no default CSS styling.

Browser Support

The HTML <base> element is supported by all modern web browsers, including Google Chrome, Mozilla Firefox, Microsoft Edge, Safari, and Opera.

It is an established HTML feature and does not require any additional library or framework.

Conclusion

The HTML <base> tag provides a simple way to define a common URL and default target for relative links in a document. It can make URL management easier, especially on pages that contain many relative paths.

However, you should use it carefully because it affects more than ordinary hyperlinks. Image paths, resource URLs, form actions, and even links to sections within the same page can be affected by its base URL.

Understanding how the href and target attributes work will help you use this element correctly in your HTML projects.

HTML

HTML Audio Tag: How to Add Audio to a Web Page

Audio can make a website more useful and engaging. For example, you might want to add background music, a podcast, a recorded lesson, or a sound effect to a web page. HTML provides a built-in <audio> element that makes this possible without requiring an external plugin.

The HTML <audio> tag allows you to embed sound files directly into a web page. You can also give visitors playback controls, set an audio file to repeat, mute its sound, or control playback with JavaScript.

1. Basic HTML Audio Example

The simplest way to add audio to a web page is to use the <audio> element with the controls attribute. This attribute displays the browser's built-in audio player, which allows visitors to play, pause, adjust the volume, and control playback.

Example

<audio controls>
    <source src="audio.ogg" type="audio/ogg">
    Your browser does not support the audio element.
</audio>

Output

In this example, the controls attribute tells the browser to display its audio player. The source element specifies the location and format of the audio file. The text inside the audio element appears if the browser does not support audio playback.

2. Using the src Attribute

You can also specify the audio file directly through the src attribute of the <audio> element. This is a shorter alternative when you only need to provide one audio file.

Example

<audio src="audio.mp3" controls>
    Your browser does not support the audio element.
</audio>

Here, the src attribute specifies the audio file. The browser uses this file as the source for playback. This approach is convenient for a single audio format, but the <source> element is more flexible when you want to provide several formats.

3. Using the autoplay Attribute

The autoplay attribute tells the browser to start playing the audio automatically when the page loads and the audio is ready.

Example

<audio autoplay>
    <source src="audio.mp3" type="audio/mpeg">
</audio>

However, modern browsers often block autoplay when the audio contains sound. This restriction helps prevent websites from playing unexpected sounds as soon as visitors open a page. Autoplay may work when the audio is muted or when the visitor has interacted with the website.

4. Using the muted Attribute

The muted attribute makes the audio start with its sound turned off. Visitors can still use the playback controls to adjust the volume if controls are provided.

Example

<audio controls muted>
    <source src="audio.mp3" type="audio/mpeg">
</audio>

In this example, the audio player appears with the sound muted by default. This can be useful when you want to provide an audio file without immediately producing sound.

5. Using the loop Attribute

The loop attribute makes the audio play repeatedly. When the file reaches the end, the browser starts it again automatically.

Example

<audio controls loop>
    <source src="audio.mp3" type="audio/mpeg">
</audio>

This attribute is useful for background sounds, music, and other audio that should repeat continuously until the visitor stops playback.

6. Providing Multiple Audio Sources

Different browsers may support different audio formats. To improve compatibility, you can provide more than one audio source inside the same <audio> element.

Example

<audio controls>
    <source src="audio.mp3" type="audio/mpeg">
    <source src="audio.ogg" type="audio/ogg">
    <source src="audio.wav" type="audio/wav">
    Your browser does not support the audio element.
</audio>

The browser checks the listed sources and uses the first format it can play. If it cannot play the MP3 file, for example, it may try the OGG or WAV file instead.

Make sure that each source points to an actual audio file. The files should contain the same recording in different formats.

7. Using the HTML embed Element for Audio

HTML also provides the <embed> element, which can be used to include external multimedia content in a web page. It can display or play certain audio files, depending on browser support.

Example

<embed
    src="audio.ogg"
    type="audio/ogg"
    width="300"
    height="50">

The src attribute specifies the audio file, while type identifies its media format. The width and height attributes define the dimensions of the embedded content.

For ordinary audio playback, the <audio> element is generally the better choice because it provides dedicated audio features and more consistent browser support.

8. Controlling Audio with JavaScript

You can use JavaScript to control audio playback. For example, the play() and pause() methods allow you to start and stop an audio file through buttons on your web page.

Example

<audio id="myAudio">
    <source src="audio.mp3" type="audio/mpeg">
</audio>

<button onclick="playAudio()">Play</button>
<button onclick="pauseAudio()">Pause</button>

<script>
    const audio = document.getElementById("myAudio");

    function playAudio() {
        audio.play();
    }

    function pauseAudio() {
        audio.pause();
    }
</script>

In this example, JavaScript selects the audio element using its ID. When a visitor clicks the Play button, the playAudio() function starts playback. The Pause button calls pauseAudio() to stop the audio temporarily.

Common Attributes of the HTML audio Element

The following table lists some commonly used attributes of the HTML <audio> element.

Attribute Description
controls Displays the browser's built-in audio playback controls.
autoplay Attempts to play the audio automatically when it is ready.
muted Mutes the audio by default.
loop Repeats the audio automatically after it finishes.
preload Hints how much audio data the browser should load before playback.
src Specifies the location of the audio file.

Conclusion

The HTML <audio> element provides a simple way to add sound to a website. Its built-in attributes make it easy to display playback controls, repeat audio, mute sound, and attempt automatic playback. You can also provide multiple audio formats to improve compatibility or use JavaScript when you need more control over playback.

For most websites, the basic <audio controls> approach is a good starting point. It gives visitors control over playback and does not force sound to play as soon as they open the page.

CSS transform-style Property

Understanding the CSS transform-style Property

Rotating cards, spinning cubes, and layered scenes all rely on CSS 3D transforms. But applying a 3D transform to an element does not automatically make its nested elements behave like real 3D objects. Whether they do depends on a small property called transform-style. This article explains what it controls, how its two values differ, and why it is behind so many confusing 3D bugs. You can also experiment with everything in the live editor further down the page.



What is the transform-style Property?

Think of a transformed element as a sheet of glass and its children as stickers on that sheet. The transform-style property decides whether the children are treated as stickers that stay on the surface of the glass, or as separate objects that each keep their own depth in front of and behind it.

The sticker behavior is the default. If you rotate a child with rotateY() or push it forward with translateZ(), the browser still applies that transform, but the result is painted onto the parent's surface. The child can never sit in front of, behind, or through other elements in a shared 3D scene. Switching on the 3D behavior removes that limit.

Definition: transform-style is a CSS property that you set on a parent element to tell the browser how to render that element's children when 3D transforms are involved. With preserve-3d, the children keep their own positions in 3D space and share one scene with the parent. With flat, the children are drawn onto the parent's two-dimensional surface and lose their independent depth.

Core Property Values

The property accepts two keywords:

  • flat (Default): Children are drawn onto their parent's surface. Their own transforms still apply, but the parent is first rendered as a single flat picture, and only that picture takes part in the parent's rotation. Because every element starts this way, you rarely need to write transform-style: flat;, except to undo a preserve-3d declared by another rule.
  • preserve-3d: Children share a 3D scene with their parent. Each child keeps its own position and rotation in depth, so siblings can overlap correctly, intersect, or sit in front of and behind each other. Use it on any transformed element whose children must keep their depth, such as a card with two faces or a cube with six.

Note that preserve-3d is not needed to rotate a single element. A lone element can be turned with transform: rotateY(180deg) and no transform-style at all. The property only matters when an element has children that must keep their 3D relationship inside it.


Practical Example: 3D Card Container (Live Editor)

To see how this works in practice, consider a common card-flipping component. The editor below contains the HTML and CSS on the left and a live preview on the right. Hover over the card in the preview to flip it, and edit either code box to see the result instantly. Without preserve-3d on the rotating container, the two faces are flattened onto the container's plane instead of living in 3D space.

HTML Structure (editable)
CSS (editable)
Live Preview (hover to flip)

Things to Try in the Editor

  • Delete the transform-style: preserve-3d; line from .card. The browser falls back to flat, both faces are flattened onto the card's plane, and the back face (already turned 180 degrees) is drawn over the front face, so the flip effect is ruined.
  • Add overflow: hidden; or opacity: 0.9; to .card. This silently forces the used value back to flat and breaks the flip.
  • Remove perspective: 600px; from .scene. The rotation still happens, but it looks flat instead of having depth.
  • Remove backface-visibility: hidden; from .card-face. The face turned away from you now shows through as a mirrored image.

How perspective and transform-style Work Together

These two properties are often confused, but they do different jobs. perspective is set on a parent and gives its direct children a sense of depth: things closer to the viewer look larger. transform-style: preserve-3d keeps the deeper descendants in that same 3D space instead of flattening them. In the example, perspective on .scene creates the viewing distance for .card, and preserve-3d on .card lets the two faces inside it share that 3D space and be drawn with the same perspective. Without perspective, the rotation still happens but looks flat and orthographic; without preserve-3d, the faces collapse into a plane.

Why the Example Needs backface-visibility

The backface-visibility: hidden; rule is not part of transform-style, but the card flip depends on it. When the card turns, the front face ends up facing away from the viewer, and by default a face turned away is still drawn as a mirrored image. Hiding the back side of each face ensures that only the face currently pointing toward the viewer is visible.


Important Usage Considerations for Developers

  • Not Inherited: transform-style is not an inherited property. If you have deep nesting, you must declare transform-style: preserve-3d on every intermediate ancestor that sits between the 3D parent and the 3D content. The 3D chain breaks at the first ancestor that is flat: everything below that element is flattened onto its plane, no matter what its own children declare. This is one of the most common reasons a 3D scene "stops working" after an extra wrapper element is added.
  • Some Properties Force flat: Certain properties require an element to be rendered as a single flattened group, and they force the used value of transform-style back to flat even if you wrote preserve-3d. This behavior is deterministic, not occasional. Common triggers include:
    • overflow set to any value other than visible or clip (for example hidden, auto, or scroll)
    • opacity with a value less than 1
    • filter and backdrop-filter with a value other than none
    • clip with a value other than auto, and clip-path with a value other than none
    • mask properties such as mask-image with a value other than none
    • isolation: isolate
    • mix-blend-mode with a value other than normal
    • contain: paint, and anything that implies it, such as content-visibility: hidden
    For example, adding overflow: hidden or opacity: 0.9 to the .card element in the live editor above would silently flatten it and break the flip. If a 3D effect stops working, check the element and its ancestors for these properties first. To fade or clip a 3D object, apply those properties to a wrapper outside the 3D structure, or to the individual faces, instead of to the element that has preserve-3d.

Conclusion

The transform-style property is small, but it decides whether nested elements behave like real 3D objects or like paint on a flat surface. When a 3D layout misbehaves, check three things in order: is preserve-3d set on every element in the chain, is perspective applied on an ancestor, and does any element in the chain use a property that forces flat?

The transform-style property also supports standard global CSS values such as inherit, initial, revert, revert-layer, and unset.

Further Reading

For the formal definition and browser support details, see the MDN Web Docs page for transform-style.

3D Animated CSS Cube

Rotating 3D Cube CSS Animation

Pure CSS 3D Cube

How to Restore or Undo Windows Photo Viewer in Windows 10/11

How to Restore or Remove Windows Photo Viewer in Windows 10/11

Windows Photo Viewer was the default image viewer in Windows 7 and 8. Later, in Windows 10 and 11, Microsoft replaced it with a different photo viewer app. This might be because Windows Photo Viewer was unable to open certain image formats. For example, images received from apps like WeChat and Telegram are not supported. However, because of its simplicity, fast performance, and clean interface, many users still prefer the classic Windows Photo Viewer. So, if you like to use Windows Photo Viewer, you can download from this blogpost and use it for free.

Note: The registry file for activating Windows Photo Viewer works on both Windows 10 and 11. If you're not so sure, you can back up your registry before applying any changes. But don’t worry, it’s safe. If it causes any issues, you can download another registry file that can undo all the changes.

Restore Windows Photo Viewer

Download and Apply Registry File

Download the registry file to restore Windows Photo Viewer:

Follow the instructions below:

  1. 1. Click the download button above, which is labeled "Restore the Windows Photo Viewer file".
  2. 2. After downloading, double-click the registry file. Click on "Run" to continue.
  3. 3. Click "Yes" when prompted by User Account Control
  4. 4. Click "Yes" to confirm and add the information to the registry.
  5. 5. Click "OK" when you see the success message
  6. 6. If the changes are not taking effect, try refreshing your PC. If the problem still persists, restart your PC to apply the changes fully.

How to Set Windows Photo Viewer as Default

After applying the registry changes:

  1. ➣ Right-click any image file and select "Open with" > "Choose another app."
  2. ➣ Select "Windows Photo Viewer."
  3. ➣Choose "Always."
  4. ➣ Boom! "Windows Photo Viewer" is now your default photo veiwing app.

Undo Windows Photo Viewer (Remove It)

If you want to remove Windows Photo Viewer and revert to the default Photos app, follow these steps:

Option A: Download and Apply Registry File (Recommended)

Download the registry file to remove Windows Photo Viewer:

  1. Click the download button above to get the registry file
  2. Save the file to your computer
  3. Double-click the downloaded .reg file
  4. Click "Yes" when prompted by User Account Control
  5. Click "Yes" to confirm you want to add the information to the registry
  6. Click "OK" when you see the success message
  7. Restart your computer for changes to take full effect

Troubleshooting

If Windows Photo Viewer doesn't appear after applying the registry changes:

  • Make sure you restarted your computer
  • Try right-clicking an image file, select "Open with" > "Choose another app" and look for Windows Photo Viewer in the list
  • If you don't see it, browse to C:\Program Files\Windows Photo Viewer and select PhotoViewer.dll
  • Some Windows 11 builds may require additional steps - try running the registry file again after a reboot

If you get errors when running the registry files:

  • Make sure you're logged in as an administrator
  • Right-click the .reg file and select "Run as administrator"
  • Check if your antivirus is blocking registry changes

Conclusion

Last but not least, I still use Windows Photo Viewer because it is very user-friendly and my favorite app for viewing images. So the two registry files above are very important: one is used to activate Windows Photo Viewer, and the other is used to undo the changes in Windows 10 and 11. Please note that Microsoft may completely remove Windows Photo Viewer in the future, so nothing is guaranteed. While it’s uncertain what will happen later, for now, at least in Windows 10 and 11, we can still use Windows Photo Viewer, and we’re quite lucky, actually.

Credits: This guide and registry files were created by Sey8. Visit our homepage at https://sey8.blogspot.com for more Windows tips and tricks.

Display flex - Responsive Layouts

My Responsive Flexbox Layout

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras a aliquet erat. Pellentesque sodales tortor massa, non facilisis sem sollicitudin sit amet. Curabitur vestibulum consectetur enim. Donec sit amet tincidunt justo. Praesent lacinia eros nec dictum cursus. Donec tempus, eros nec viverra fringilla, erat orci vestibulum diam, vitae tristique eros ex et est. Pellentesque venenatis, turpis quis suscipit consequat, lectus mi auctor odio, nec fermentum dolor nulla in odio. Duis fringilla, libero quis tristique suscipit, risus nisi tincidunt mauris, vitae efficitur leo quam id odio. Praesent diam ligula, consequat vel aliquet vitae, vestibulum eu neque.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras a aliquet erat. Pellentesque sodales tortor massa, non facilisis sem sollicitudin sit amet. Curabitur vestibulum consectetur enim. Donec sit amet tincidunt justo. Praesent lacinia eros nec dictum cursus. Donec tempus, eros nec viverra fringilla, erat orci vestibulum diam, vitae tristique eros ex et est. Pellentesque venenatis, turpis quis suscipit consequat, lectus mi auctor odio, nec fermentum dolor nulla in odio. Duis fringilla, libero quis tristique suscipit, risus nisi tincidunt mauris, vitae efficitur leo quam id odio. Praesent diam ligula, consequat vel aliquet vitae, vestibulum eu neque.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras a aliquet erat. Pellentesque sodales tortor massa, non facilisis sem sollicitudin sit amet. Curabitur vestibulum consectetur enim. Donec sit amet tincidunt justo. Praesent lacinia eros nec dictum cursus. Donec tempus, eros nec viverra fringilla, erat orci vestibulum diam, vitae tristique eros ex et est. Pellentesque venenatis, turpis quis suscipit consequat, lectus mi auctor odio, nec fermentum dolor nulla in odio. Duis fringilla, libero quis tristique suscipit, risus nisi tincidunt mauris, vitae efficitur leo quam id odio. Praesent diam ligula, consequat vel aliquet vitae, vestibulum eu neque.

Add HTML Document and CCS to New Context Menu

Watch the video at  https://youtu.be/1ubdy1cL2PI for the instruction:-

HTML and CSS at New context menu

1. For HTML File


2. For CSS File

Transform-origin In CSS

The CSS property transform-origin defines the point around which a transformation is applied to an element. It is the point or origin of the transform property which can change the point of transformations like rotation, scaling, skewing, etc. By default, the transform-origin of an element is relative to the center of an element.

Transform-origon CSS

-

Video Tutoral at https://youtu.be/-MZvSn6pOyg

The transform-origin property is used along with the transform property. For example, if we use, transform: rotateZ(30deg); and transform-origin: top;, the point of transformation or rotation starts from the top center.

If you want to keep the transform-origin at the center, then there is no need to use the transform-origin property. This is because the transform-origin is at the center by default. However, if you want to shift your transform-origin, then you have to use it.

If we set here the transform-origin: bottom;, then the transform-origin is at the bottom center. Similarly, you can set transform-origin: left;, transform-origin: right;, transform-origin: top;, transform-origin: top right;, transform-origin: bottom left;, etc.

transform-origin: top right; Here the transform-origin has shifted to the top right corner.

Instead of using transform-origin: right bottom;, we can use transform-origin: 100% 100%;. Here, the first value is x, and the second value is y. Both x and y move 100% away from 0, intersecting at the right bottom corner. So, transform-origin: 100% 100%; is the same as transform-origin: right bottom;.

transform-origin: 50%; : Here, 50% represents the X value. Even though nothing is mentioned for Y, it still means that the Y value is 50% by default.

transform-origin: 50% 50%; : In this case, we find that both the x and y values are each specified as 50%.

transform-origin: 50% 0; : Here, the x value is 50% and the y value is 0, which sets the transform-origin to the top center.

Here are some examples of transform-origin values that give the same effects. Please go through all of these:


/* Left transform-origin */
transform-origin: 0;
transform-origin: left;
transform-origin: center left;
transform-origin: left center;
transform-origin: 0 50%;

/* Top left transform-origin */
transform-origin: top left;
transform-origin: left top
transform-origin: 0 0;

/* Top transform-origin */
transform-origin: top; 
transform-origin: top center;
transform-origin: center top;
transform-origin: 50% 0;

/* Top right transform-origin */
transform-origin: top right;
transform-origin: right top;
transform-origin: 100% 0;

/* Right transform-origin */
transform-origin: right;
transform-origin: 100%;
transform-origin: center right;
transform-origin: right center;
ransform-origin: 100% 50%;

/* Bottom right transform-origin */
transform-origin: bottom right;
transform-origin: right bottom;
transform-origin: 100% 100%;

/* Bottom transform-origin */
transform-origin: bottom;
transform-origin: bottom center;
transform-origin: center bottom;
transform-origin: 50% 100%;

/* Bottom left transform-origin */
transform-origin: bottom left;
transform-origin: left bottom;
transform-origin: 0 100%;

Index

CSS

Result
transform-origin: 50% 100%;

Hover your mouse on the above square.

Transform-origin: x-offset value, y-offset value, z-offset value; This is the main syntax for transform-origin values. We have x-offset value which defines the horizontal position of the origin. The second one is y-offset value which defines the vertical position of the origin and the third is z-offset value which defines the position along the z-axis (depth) when using 3D transformations.

Transform-origin value can be one-value syntax, two-value syntax and three-value syntax. The three-value syntax can be used specially in a 3D element. Here are examples of one-value syntax, two-value syntax, and three-value syntax. Please go through all of these. Please note that z-offset cannot be used in percentage because there is no measurable or clear size on the z-axis.

Examples:


/* 1. One-value syntax */
transform-origin: 3px;
transform-origin: top;

/* 2. Two-value syntax */
transform-origin: 5cm 3px;
transform-origin: 80% 30%;
transform-origin: left 2px;
transform-origin: right top;
transform-origin: top right;

/* 3. Three-value syntax */
transform-origin: 2px 30% 10px;
transform-origin: left 5px -4px;
transform-origin: right bottom 5cm;
transform-origin: bottom right 9cm;

We can also use Global Values in transform-origin. Here, we have:


/* Global values: */
transform-origin: inherit; 
transform-origin: initial; 
transform-origin: revert; 
transform-origin: revert-layer; 
transform-origin: unset; 

In CSS, global values control how properties are applied or reset by inheriting values, using default settings, or reverting to previous or default states.

So in conclusion, the transform origin is very useful when we animate or style our transformations. By changing the transform origin, we can make the visual effect of an element look much better.

.
US Flag
play button