Skip to content


Design System
Home Design System Guidelines Scripts


These reference scripts demonstrate additional functionality required to enhance SDS




The following reference script observes the resizing of any element that has a data-attribute data-ds-size. It then creates and dynamically updates css vars with naming based on the value of the data-ds-size attribute value, and adds a class to element if it is overflowing. This is then used by SDS for dynamically calculating element offset (such as scrolling to anchors) and triggering mobile display in certain situations.

HTML element with data-attribute
<div data-ds-size="my-element">
  ... content ...
Javascript observing matching elements for resize
// Observe ds-elements with the required data-attribute and update css vars with their dimensions
if ("ResizeObserver" in window) {
  const dsElements = document.querySelectorAll("[data-ds-size]");

  const observer = new ResizeObserver(elements => {
    elements.forEach(element => {
      const width =; // Displayed width of element
      const scrollwidth =; // Actual width of content
      const height =;
      const { top, left } =;

      // Get the value of the attribute to use in the css var name
      const propertyName =
      // Check overflow
      // As soon as this element transitions from not-overflowing to overflowing save the
      // current width as a data-attribute and add a class to indicate this element is now overflowing
      if (scrollwidth > width && !'ds-overflow')) {'data-ds-overflow-width', width);'ds-overflow', true);
      // As the element no longer overflowing, now check if the element
      // is wider than the last recorded overflow width, if so update
      else if (width >'data-ds-overflow-width')) {'data-ds-overflow-width', '');'ds-overflow', false);

      // Set the css vars on the root html element
      const htmlElement = document.documentElement;"--ds-" + propertyName + "-height", height + "px");"--ds-" + propertyName + "-width", width + "px");"--ds-" + propertyName + "-top", top + "px");"--ds-" + propertyName + "-left", left + "px");

  dsElements.forEach(elements => {
Resulting css vars dynamically updated (the height/width below will update based on the dimensions of the element)
html {
  --ds-my-element-height: 60px;
  --ds-my-element-width: 1100px;
  --ds-my-element-top: 100px;
  --ds-my-element-left: 50px;
Resulting html updated (the class ds-overflow will be added if the element has overflowing content)
<div data-ds-size="my-element" class="ds-overflow">
  ... content ...