Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8851265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:06:47+00:00 2026-06-14T13:06:47+00:00

I would like to make a css transition on an element which has display:

  • 0

I would like to make a css transition on an element which has display: none set. Consider the following code:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>CSS Transition From Hidden</title>

        <style type="text/css">
            div {
                -webkit-transition-property: all;
                -webkit-transition-duration: 2s;
            }       

            div.hidden {
                display: none;
                opacity: 0;
            }    

            div.from {
                opacity: 0;
            }
        </style>     

        <script type="text/javascript">
            function loaded() {
                var e = document.getElementById("foo");
                e.className = "from";
                window.webkitRequestAnimationFrame(function(t) {
                    e.className = null;
                });
            }
        </script>
    </head>
    <body onload="loaded()">
        <div id="foo" class="hidden">
            My test div
        </div>
    </body>
</html>

I would like to go from class="div.hidden" to class="", i.e. from display: none; opacity: 0; to display: block; opacity: 1; However, in chrome (at least) an object that has display: none does not animate. The element goes to the end state immediately.

My work around for this is to first set the element to display: block; opacity: 0; and then do the transition in the next frame (using requestAnimationFrame(). It is kind of awkward, and I can’t find any explanation for this behavior in the spec. I know that I could use the visibility-attribute, but I don’t want to use it because I don’t want to layout the hidden element.

So, the questions are: Is this the correct behavior or a bug? If it is the correct behavior, is there a better way to write the code? Note that I’m not asking if there are any libraries that can do it, I want to know if there is a better way to do it directly on the DOM.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T13:06:48+00:00Added an answer on June 14, 2026 at 1:06 pm

    Regarding the question on if this is in the spec, there is an interesting thread on the www-style@w3.org list here. I haven’t read it all but it seems as they don’t start animations from none and that the transition spec needs to clarify that as well.

    Update: I have asked the mail list and I got this link to the minutes of a work group meeting where it was decided that there should be no transition if the start state is display: none.

    To make sure that the transition is performed you must make sure that the value of the animated property is calculated before it is set to its new target. Values are normally not calculated when display is set to none. Here is a working example:

    <!DOCTYPE HTML>
    <html>
      <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8">
    
        <title>Fade</title>
    
        <style>
          .hidden { display: none }
          .start { opacity: 0 }
          .transition { opacity: 1; -webkit-transition: opacity 1s }
        </style>
      </head>
      <body>
        <div id='div' class="hidden">Test</div>
    
        <script>
          var elem = document.getElementById('div');
    
          function ontransitionend(event) {
            elem.className = null;
            elem.removeEventListener('transitionend', ontransitionend);
          }
          elem.addEventListener('transitionend', ontransitionend);
    
          elem.className = 'start';
          window.getComputedStyle(elem).opacity;
          elem.className = 'transition';
        </script>
      </body>
    </html>
    

    Note that you have to access the opacity property. It is not enough to call getComputedStyle()!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i would like to learn how to make PHP/CSS syntax generator. i assume this
I would like make an extension method for the generic class A which takes
I downloaded http://code.google.com/chrome/extensions/samples.html#ea2894c41cb8e80a4433a3e6c5772dadce9be90d . I would like make it it jQuery, but if i
I would like to make a custom button, that will display 3 data bound
I have three layers, two of which are hidden using CSS. I would like
I would like make a script using PHP (probably need JS) to send POST
Would like to make anapplication in Java that will not automatically parse parameters used
I would like to make sure my classes are robust - even if they
I would like to make a password and username entry field. And a submit
I would like to make a JSF inputText field into upper case when the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.