NEW POSTS
latest
CSS
CSS

Pages

Contact Form

Name

Email *

Message *

Latest Articles

Base Tag in HTML

HTML <base> Tag

When building a website, you may need to link to several pages, images, documents, and other resources. Some of these links use complete web addresses, whereas others contain only a relative path. The HTML <base> tag helps manage these relative paths by defining a common starting URL for the entire document.

It can also specify where hyperlinks and form submissions should open by default. This means you can establish a default destination and browsing context without repeating the same information in every link.

The <base> element belongs inside the <head> section of an HTML document. It does not display anything on the webpage, but its settings influence how the browser handles URLs throughout the document.

Syntax of the HTML <base> Tag

The general syntax is:

<base href="URL" target="browsing-context">

The element has two main attributes: href and target. You can specify either one or use both in the same element.

Understanding the href Attribute

The href attribute establishes the base URL for resolving relative URLs in an HTML document. Whenever the browser encounters a relative path, it uses this address as the starting point to determine the complete destination.

For example, suppose you want the relative links on your website to use the following address as their starting point:

https://sey8.blogspot.com/

You can define it in the document's head section as follows:

<head>
    <base href="https://sey8.blogspot.com/">
</head>

Now consider these two elements:

<a href="tutorials/html-guide.html">HTML Guide</a>

<img src="images/html-cover.jpg" alt="HTML Guide Cover">

Because both paths are relative, the browser combines them with the base URL. Their resulting addresses are:

  • https://sey8.blogspot.com/tutorials/html-guide.html
  • https://sey8.blogspot.com/images/html-cover.jpg

These are illustrative paths. The corresponding pages and image must exist at those locations for the links and image to work.

Without a base URL, the browser would resolve relative paths against the URL of the current document. By defining a base URL, you can change the starting point used for those paths.

Relative URLs and Absolute URLs

It is important to understand the difference between relative and absolute URLs when using the <base> element.

A relative URL contains a path that the browser must resolve against a base address. For example:

pages/contact.html
images/logo.png
../documents/manual.pdf

An absolute URL provides a complete address, including the scheme and domain. For example:

https://www.wikipedia.org/
https://www.google.com/
https://sey8.blogspot.com/

The href attribute of the <base> element affects relative URLs. It does not replace an absolute URL with the base address.

For example, if your document contains the following link:

<a href="https://www.wikipedia.org/">Wikipedia</a>

The browser still opens Wikipedia, even if the document has this base URL:

<base href="https://sey8.blogspot.com/">

Understanding the target Attribute

The target attribute determines the default browsing context for hyperlinks and form submissions. In simpler terms, it controls where the browser opens a linked page or displays the result of a form submission.

For example, you can set the default target to a new browser tab:

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

After this setting, hyperlinks without their own target attribute will normally open in a new tab.

HTML provides four commonly used target keywords:

Target Value Purpose
_self Opens the destination in the current browsing context. This is the default behaviour.
_blank Opens the destination in a new browsing context, usually a new tab.
_parent Opens the destination in the parent frame. If no parent frame exists, it behaves like _self.
_top Opens the destination in the top-level browsing context, outside any frames.

You can also use a custom name as the target value. This allows multiple links to navigate to the same named browsing context.

Overriding the Default Target

The target specified in an individual hyperlink takes priority over the default target established by the <base> element.

Consider the following example:

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

    <a href="https://sey8.blogspot.com/">Visit My Blog</a>

    <a href="https://www.wikipedia.org/" target="_self">
        Visit Wikipedia
    </a>

</body>

The first link opens in a new tab because it follows the default target. The second link opens in the current tab because it explicitly specifies target="_self".

Using Both Attributes Together

You do not need separate <base> elements to define the default URL and target. Both attributes can be included in a single element.

For example:

<head>
    <base href="https://sey8.blogspot.com/" target="_blank">
</head>
<body>

    <a href="tutorials/css-guide.html">CSS Guide</a>

    <a href="tutorials/javascript-guide.html">JavaScript Guide</a>

</body>

In this example, both relative links use your blog's root URL as their starting point. They also open in new tabs because the default target is set to _blank.

The browser resolves the destinations as follows:

  • https://sey8.blogspot.com/tutorials/css-guide.html
  • https://sey8.blogspot.com/tutorials/javascript-guide.html

This approach can be useful when several links share the same base address and opening behaviour.

How the Base Tag Affects Other HTML Elements

The effect of the <base> element is not limited to hyperlinks. Its base URL is also used to resolve relative URLs in other elements that refer to external resources.

Here are some common examples:

  • Images: The src attribute of an <img> element.
  • Stylesheets: The href attribute of a <link> element.
  • JavaScript files: The src attribute of a <script> element.
  • Forms: The action attribute of a <form> element.
  • Other resources: URL references in elements such as <audio>, <video>, and <iframe>.

For example, suppose you have defined this base URL:

<base href="https://sey8.blogspot.com/">

The following image and stylesheet references will use that address:

<img src="media/banner.jpg" alt="Website Banner">

<link rel="stylesheet" href="styles/main.css">

The browser will look for the files at:

https://sey8.blogspot.com/media/banner.jpg

https://sey8.blogspot.com/styles/main.css

This behaviour can save you from writing the same domain and directory path repeatedly. However, you must make sure that the referenced files actually exist at the resulting locations.

Important Rules When Using the <base> Element

Although the <base> element is simple to use, there are a few important rules to follow.

  1. Only one base element is allowed. An HTML document must not contain more than one <base> element. If multiple elements are present, browsers use only the first applicable href and first applicable target values.
  2. It must be placed inside the head section. The <base> element belongs in the document's <head>, not in the <body>.
  3. At least one attribute is required. You must provide an href attribute, a target attribute, or both.
  4. Position matters. When the element has an href or target attribute, place it before other elements that use URL attributes or create hyperlinks, as applicable.
  5. It does not have a closing tag. The <base> element is a void element. Write it as a single tag rather than adding </base>.
  6. Individual targets can override the default. A hyperlink or form with its own target attribute uses that value instead of the default target.

How Does the Base Tag Affect Links to Sections on the Same Page?

One detail that developers sometimes overlook is how the <base> element handles fragment links. A fragment link normally points to a particular section of the current page using an element's id attribute.

For example:

<a href="#features">View Features</a>

<h2 id="features">Website Features</h2>

Under normal circumstances, clicking the link moves the browser to the section identified by features.

However, if you have specified a base URL, the browser resolves the fragment against that address. For example:

<base href="https://sey8.blogspot.com/">

With this setting, the link #features resolves to:

https://sey8.blogspot.com/#features

This may take the visitor to a different document or location rather than the section they expected to reach in the current page.

If your page uses a base URL and you want a link to point to a section of the current document, use the complete URL of that document followed by the fragment identifier.

Can the Base Tag Have a Relative URL?

Yes. The href attribute does not always need to contain a complete web address. It can also use a relative URL.

For example:

<base href="../resources/">

In this case, the browser resolves the base URL against the document's original URL. Other relative paths in the document are then resolved using the resulting base address.

However, an absolute URL is often easier to understand because it clearly identifies the website and directory that should serve as the starting point.

Also, the href attribute must not use the data: or javascript: URL schemes.

Does the <base> Tag Support Global Attributes and Events?

The <base> element supports HTML global attributes, which are attributes that can be used on most HTML elements.

However, it does not provide specific event handler attributes for handling user interactions. It is a metadata element and does not represent a visible or interactive part of the webpage.

It also has no default CSS appearance because it does not render visible content.

Browser Compatibility

The HTML <base> element is supported by all major modern web browsers, including:

  • Google Chrome
  • Mozilla Firefox
  • Microsoft Edge
  • Apple Safari
  • Opera

It is a well-established HTML feature and does not require JavaScript, CSS libraries, or any additional framework to work.

In Summary

The HTML <base> tag provides a convenient way to define the starting URL and default browsing context for an HTML document. Its href attribute controls how relative URLs are resolved, whereas its target attribute determines where links and form submissions open by default.

Although it can simplify URL management, you should use it carefully. A base URL can affect images, stylesheets, scripts, form destinations, and even links to sections within the same page. A small change to this element can therefore influence several parts of a website.

Once you understand how these two attributes work, you can decide when the <base> element is useful and avoid unexpected navigation or resource-loading problems in your HTML projects.

Audio Tag in 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