Skip to content

Implement calc() and other math functions #357

Closed

Description

@Akay7

Function calc of css not working :(

/* property: calc(expression) */
width: calc(100% - 80px);

https://developer.mozilla.org/en/docs/Web/CSS/calc

Activity

  1. changed the title [-]Css function calc not work[/-] [+]Implement calc()[/+] on Sep 13, 2016
  2. added
    featureNew feature that should be supported
    on Sep 13, 2016
  3. dennisvang commented on Apr 14, 2021

    @dennisvang

    For those interested, here's the nitty gritty: https://drafts.csswg.org/css-values-3/#calc-notation

  4. whinee commented on Feb 14, 2023

    @whinee
    Contributor

    Please mention that calc() is yet to be implemented in the documentation. This might save devs that uses this project hours or even weeks of pain, debugging what might be wrong with their HTML/CSS. Thank you!

  5. liZe commented on Feb 14, 2023

    @liZe
    Member

    Hi!

    This might save devs that uses this project hours or even weeks of pain, debugging what might be wrong with their HTML/CSS.

    If you want to avoid "weeks of pain", you can read the logs: warnings are logged each time a property or a value is not supported.

    Please mention that calc() is yet to be implemented in the documentation.

    You’re right, that would be very useful. Interested in opening a pull request? That would be a quite simple way to become a contributor!

  6. whinee commented on Feb 14, 2023

    @whinee
    Contributor

    Hallo!

    If you want to avoid "weeks of pain", you can read the logs: warnings are logged each time a property or a value is not supported.

    Turns out that not reading docs properly also causes this. Thanks for reminding me. Time to turn on logging.

    You’re right, that would be very useful. Interested in opening a pull request? That would be a quite simple way to become a contributor!

    Contrary to my comment above, I love reading docs! Though I am not confident that I will be able to write it. I mean I can, just not properly. I guess I'll try???

    Anyways, I have just re-read my comment, and I think it might have sounded rude, and I feel bad for it now, sorryy... I tried to make it short 'cause every issue / comment I write sounds childish...

  7. liZe commented on Feb 14, 2023

    @liZe
    Member

    Anyways, I have just re-read my comment, and I think it might have sounded rude, and I feel bad for it now, sorryy... I tried to make it short 'cause every issue / comment I write sounds childish...

    No problem!

    Contrary to my comment above, I love reading docs! Though I am not confident that I will be able to write it. I mean I can, just not properly. I guess I'll try???

    Adding a sentence here is sufficient:

    You can copy another line where a property is not supported. And don’t worry, it doesn’t have to be perfect, we can always enhance it afterwards!

  8. grewn0uille commented on Oct 23, 2023

    @grewn0uille
    Member

    Hello!

    As you may know, two weeks ago was CourtBouillon 3-year anniversary 🎉.

    For this occasion, we prepared a short survey to have your opinion on this year’s features and to know what you’d like to see in the future!
    Don’t hesitate to give a boost to this feature ✨️

    The survey is opened until November 19.

  9. anasvikh commented on Dec 5, 2023

    @anasvikh

    Hi!
    Do you have any updates for this feature?

  10. liZe commented on Dec 5, 2023

    @liZe
    Member

    Hi!

    Hi!

    Do you have any updates for this feature?

    Great timing! We’ve just talked about it in #1219.

    Current status: we’ve just cleaned the code that takes care of CSS values validation, in order to get a more solid support of var(). When the latest missing features for var() are added (non-shorthand properties with multiple values, functions), we’re ready to look at other functions such as calc(). There’s probably a lot of work left, but at least we now have clean code we can rely on to validate values that include functions.

  11. easyjoh commented on Feb 3, 2024

    @easyjoh

    if there any work-around for calc in width of table?
    I have a nested table which need to have the width: calc(100% + 0.25mm); can I somehow make the long walk to get it working before the calc is implemented?

  12. liZe commented on Feb 4, 2024

    @liZe
    Member

    if there any work-around for calc in width of table?

    I’m afraid there’s no easy workaround for your case. Setting negative left and right margins to -0.25mm may help.

  13. changed the title [-]Implement calc()[/-] [+]Implement calc() and other math functions[/+] on May 22, 2024
  14. majorisgit commented on Jul 20, 2024

    @majorisgit

    Hello,

    When will calc() be implemented?
    Are there any alternatives?

    Thanks

  15. liZe commented on Jul 20, 2024

    @liZe
    Member

    Hi!

    When will calc() be implemented?

    We have no roadmap for this feature. That’s a complex feature that requires quite a lot of work.

    Are there any alternatives?

    As explained above, not really. Using a CSS preprocessor like Sass can help in some cases.

  16. mbarkhau commented on Sep 30, 2024

    @mbarkhau
    Contributor

    Would an initial implementation be possible, that doesn't require context? So if we say, we don't css variables and also font size in the current scope are initially off the table, could calc be implemented for very basic expressions such as these: calc(4.75 * 4)mm, calc(2 * 9pt) ?

  17. liZe commented on Sep 30, 2024

    @liZe
    Member

    Yes, now that we have #1219 fixed, the situation is much better than before, and we can imagine solving this kind of examples. Even the "context" shouldn’t be a problem (as we already need much more for var()), we "only" need quite some dedicated time to write the required code.

    (I was a bit afraid with your example, but I’m calc(4.75 * 4)mm is actually invalid, we have to use calc(4.75 * 4mm) instead!)

  18. lunarcloud commented on Nov 15, 2024

    @lunarcloud

    Any news or progress on this?
    We would love to use calc in our own styles to make variables more useful and to utilize some calc(100% + var(--some-amount))

  19. liZe commented on Nov 15, 2024

    @liZe
    Member

    Hi!

    Any news or progress on this?

    No. As explained above, we "only" need to find dedicated time to solve this issue. As the problem is a bit complex, if the feature is not sponsored, it requires a pretty long period of free time to focus, and that’s something we don’t often have (you probably know what I’m talking about 😄).

  20. alexmarkley commented on Mar 30, 2025

    @alexmarkley

    I worked around this issue (as well as this one in particular: #1194) by incorporating LESS into my script to preprocess the CSS that weasyprint actually sees.

    After all, "my browser doesn't support X" is one of the main use cases for CSS preprocessing. So it's a natural fit.

  21. liZe commented on Nov 10, 2025

    @liZe
    Member

    Closed by #2568. Manual tests and bug reports are warmly welcomed!

  22. added this to the 67.0 milestone on Nov 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureNew feature that should be supported

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions