Master of Science Thesis University of Turku Department of Computing Computer Science November 2023 Julius Virtanen Dark Mode Preferences: Exploring User Motivations in Interface Theme Selection The originality of this thesis has been checked in accordance with the University of Turku quality assurance system using the Turnitin Originality Check service. UNIVERSITY OF TURKU Department of Computing, Faculty of Technology VIRTANEN, JULIUS: Dark Mode Preferences: Exploring User Motivations in Interface Theme Selection Master of Science Thesis, 80 pages, 1 appendix page. November 2023 In a world that is increasingly digital, the interfaces through which we interact with our technology play a critical role in our daily experiences. One important aspect of interface design is theming, which allows users to personalize their visual interaction with software applications and websites. Theming itself is a varied concept, but it enables users to tailor their digital environments according to their preferences, thereby enhancing usability and user satisfaction. Among various theming options, ’Dark mode’ has risen to prominence as a notable design trend in recent years. The adoption of Dark mode by major software platforms and applications signifies its impact and growing relevance. However, the key factors that lead to its adoption are highly debated among end users. In addition, many websites and applications have yet to incorporate a Dark mode feature. For this reason, understanding what leads to these preferences has practical implications for web developers and designers as well. To better understand and evaluate the motivations behind users’ Dark mode theme selection, a survey was conducted. The survey employed a questionnaire where the questions were rooted in a set of background hypotheses that are believed to be influential in determining why users opt for Dark or Light mode. These background hypotheses were formed using the literature existing in the field. The results of the survey suggest that there is no single driver for Dark mode selection, rather, users might be weighing Dark mode’s visual appeal against functional benefits like reduced eye strain, focus, power savings, and select a theme based on these assumptions. A subset of users also tailor their own interfaces more than others, where the implications of application specificity rises to question. In addition, age also plays a factor in the selection, but only to a degree. Keywords: Dark mode, User-interface, UI Design, Usability, Screen time, Readability, Power Consumption, Accessibility, Questionnaire TURUN YLIOPISTO Tietotekniikan laitos, Teknillinen tiedekunta VIRTANEN, JULIUS: Mieltymykset tummaan teemaan: Käyttöliittymäteeman valintaan johtavat tekijät Pro gradu -tutkielma, 80 sivua, 1 liitesivu. Marraskuu 2023 Digitaalisessa vuorovaikutuksessa käyttöliittymät ovat keskiössä. Yksi tärkeä käyttöliittymäsuunnittelun näkökulma ovat teemat, joiden avulla käyttäjät voivat yksilöidä oman kokemuksensa sovelluksissa ja verkkosivustoilla. Teemojen käyttö on monipuolinen ilmiö, mutta viime kädessä ne sallivat käyttäjien mukauttaa digitaalista ympäristöään heidän mieltymystensä mukaisesti parantaen näin käytettävyyttä ja käyttäjätyytyväisyyttä. Yksi suosituimmista teemavaihtoehdoista on ’Tumma tila’ eli ’Dark Mode’. Se on noussut merkittäväksi trendiksi viime vuosina erityisesti suurten ohjelmistoyritysten ja suosittujen sovellusten vauhdittamana. Kuitenkin ne avaintekijät, jotka johtavat sen käyttöönottoon, ovat kiistanalaisia. Näistä tekijöistä myös käydään kiivaita keskusteluja loppukäyttäjien joukossa. Lisäksi monet verkkosivustot ja sovellukset eivät ole vielä sisällyttäneet Dark Mode -ominaisuutta alustalleen. Tästä syystä teemamieltymysten ymmärtäminen on tärkeää myös web-kehittäjille ja sovellusten suunnittelijoille. Käyttäjien teeman valintaperusteiden ymmärtämisen ja arvioinnin parantamiseksi suoritettiin kattava kyselytutkimus. Kyselyssä käytettiin kyselylomaketta, jonka kysymykset perustuivat taustaoletuksiin, joiden uskotaan vaikuttavan käyttäjien päätöksiin valita joko tumma tai vaalea teema. Nämä taustaoletukset muodostettiin olemassa olevan alan kirjallisuuden perusteella. Kyselytutkimuksen tulokset viittaavat siihen, että tumman teeman valintaan ei ole yksittäistä merkittävää tekijää. Sen sijaan käyttäjät saattavat punnita tumman teeman visuaalista viehätysvoimaa toiminnallisiin hyötyihin, kuten esimerkiksi silmien rasituksen vähentämiseen, keskittymiseen, virrankulutukseen ja valita näiden olettamusten perusteella oman teemansa. Osa käyttäjistä myös mukauttaa omia käyttöliittymiään enemmän kuin toiset, jolloin sovelluskohtaiset valinnat tulevat ilmi. Lisäksi ikä vaikuttaa valintaan, mutta ainoastaan tietyssä määrin. Asiasanat: tumma teema, käyttöliittymä, käyttöliittymämuotoilu, käytettävyys, näyttöaika, luettavuus, virrankulutus, saavutettavuus, kyselylomake Table of Contents 1. Introduction ....................................................................................................... 1 1.1 Background and Goals ............................................................................... 1 1.2 Structure...................................................................................................... 2 2. Graphical User Interfaces ................................................................................ 3 2.1 History of User Interfaces .......................................................................... 5 2.2 Modern User Interfaces and Web Content .............................................. 11 3. Theming and Styling ....................................................................................... 15 3.1 Cascading Style Sheets (CSS) .................................................................. 16 4. The Rise of ‘Dark Mode’ ................................................................................ 20 4.1 Dark Mode Implementation ..................................................................... 22 4.2 Previous Research and Related Work ...................................................... 27 5. Dark Mode Survey Design ............................................................................. 34 5.1 Research Methodology ............................................................................. 34 5.2 Data Collection Method ........................................................................... 36 6. Results and Analysis ....................................................................................... 38 6.1 Overview .................................................................................................. 38 6.2 Comparison ............................................................................................... 66 6.3 Discussion ................................................................................................. 71 7. Conclusion ........................................................................................................ 74 7.1 Future Work .............................................................................................. 75 References ............................................................................................................ 76 Appendices ........................................................................................................... 80 Appendix A – Dark Mode Preferences Survey ............................................. 80 Appendix B – Survey Results ........................................................................ 80 1 1. Introduction In a world that is increasingly digital, the interfaces through which we interact with our technology play a critical role in our daily experiences. One aspect of interface design that has gathered large amounts of attention is theming, which allows users to personalize their visual interaction with software applications and websites. Theming itself is a varied concept, confining everything from colour schemes and typography to layout and iconography. It enables users to tailor their digital environments according to their preferences, thereby enhancing usability and user satisfaction. Among various theming options, ’Dark mode’ has risen to prominence as a notable design trend in recent years. Dark mode is a user interface option that reverses the default colour scheme, primarily using dark backgrounds with lighter text and interface elements. Originally an option which was commonplace for developers and tech enthusiasts, Dark mode has now mainstreamed, becoming a frequently debated topic among everyday users. The adoption of Dark mode by major software platforms and applications signifies its impact and growing relevance. 1.1 Background and Goals Despite Dark mode growing in popularity, the reasons behind choosing Dark mode or conversely, sticking with the default ’Light mode’ vary among users. While some users advocate the benefits of Dark mode, such as reduced eye strain and battery saving or even privacy, others prefer the traditional light mode for its perceived readability and brighter appearance. Many websites and applications have yet to incorporate a Dark mode feature. For this reason, understanding what leads to these preferences has practical implications for web developers and designers. It can inform the people who are contemplating whether to allocate resources for embracing new theming options like Dark mode into their platforms. This leads us to our central research question: What factors motivate people to choose a different theme or change to a Dark mode in various software applications and websites? 2 To address this question, this thesis employs a survey method aimed at uncovering why users prefer one mode over another. By evaluating these preferences this study aims to deliver practical recommendations that could guide future design and development of user interfaces and even guide further Dark mode research. Furthermore, the findings could reveal patterns or factors previously overlooked, such as specific use-cases where one mode may be more beneficial than the other, or demographic variations in theme preferences. The information gained here could be valuable for web developers and designers, but also for software companies and digital content providers looking to enhance user experience and engagement. 1.2 Structure This thesis is organized into several chapters, each focused on a different aspect of the interface topic. After this introduction, Chapter 2 explains the basics of graphical user interfaces, the history, and the development of user interfaces to set the stage for current trends. Chapter 3 covers theming and styling of graphical user interfaces, specifically going over cascading style sheets and their technicalities. This works as a transition for the Dark mode Chapter 4, which goes in-depth with the rising trend of dark theming, Dark mode implementation, and previous research regarding these theming options. Later in Chapter 5, we discuss the design of the research survey, particularly research methodology and data collection of our survey. Following that, Chapter 6 presents the results and analysis of this survey, exploring the collected data and what implications it might have regarding our research question about users’ theming preferences. Finally, Chapter 7 concludes the thesis, summarizing the findings and suggesting future research areas. Additional materials, such as the survey questions and collected data, can be found in the appendices. 3 2. Graphical User Interfaces Graphical user interfaces (GUIs) serve as the bridge between humans and computers, streamlining interaction and facilitating a multitude of tasks [1]. While interfaces can exist in various forms, this thesis will focus primarily on graphical user interfaces and their web-based variations. These interfaces are what users encounter on various platforms like computer monitors, smartphone screens, tablets, and other digital displays. The fundamental purpose of a graphical user interface, as Donald Norman [2] suggests, is to serve as a digital extension of real-world tools and functions, thereby enhancing intuitive use. Given that people are already accustomed to interacting with buttons, levers, and switches in the physical real world, incorporating these elements into a digital context feels natural as users directly manipulate and toy with them. The graphical user interface also offers navigational guidance. Through recognizable icons and symbols - such as a magnifying glass for search, a menu icon for options, signal bars for wireless networks, and a diskette for saving - users receive visual cues that inform them of their actions. This is based on what Norman [2] calls ‘mental models’, or the ideas we already have about how things should work. These models make it easier for us to use new digital tools, whether it is a desktop application or a website on a mobile device. Now, how does a computer know to show these helpful icons and layouts? That is where the basics of GUI design come in. In traditional desktop GUIs, there are usually three foundational components that work together to form the basic user interface. The first is the windowing system, responsible for the structure and layout of windows, menus, and dialog boxes on the screen. The second is the imaging model, which defines the visual elements such as fonts and graphics that are displayed. Lastly, there is the Application Program Interface (API). This is the set of protocols and tools that allow users to specify how windows and graphics should appear and behave on the screen [1]. While this explanation simplifies the complexities of window managers and the underlying technologies, it offers a useful high-level overview of how GUIs operate. 4 To illustrate how these principles still apply - even in modern systems like Apple's MacOS Ventura, these basics still play a critical role in making technology user-friendly and familiar as seen in Figure 1. Figure 1. MacOS Ventura 13 Desktop GUI, https://support.apple.com/guide/mac-help/work-on-the-desktop- mh40612/mac With the advent of the Internet and the high adoption of mobile devices, it is important to note that desktop environments are not the only platforms where GUIs are relevant. Web and mobile interfaces have gained popularity as an increasingly significant category within the landscape of user interfaces. This shift to more varied digital platforms has been driven by emerging technological advancements such as cloud services and high- speed internet availability [3]. This multi-platform expansion of GUIs not only diversifies the types of interfaces available but also greatly influences user expectations and experiences. For instance, modern users often expect seamless transition, customizability and consistent functionality across desktop, web, and mobile applications. This presents challenges for designers and developers of new graphical user interfaces [4]. Take for instance Discord in Figure 2., an instant messaging application which needs to adapt to different devices and environments, while still retaining all its functionality. 5 Figure 2. Discord desktop and mobile views compared, https://discord.com/blog/how-discord-made-android- in-app-navigation-easier But before we inspect any specific challenges developers and designers face, let us delve into the evolution of visual user interfaces, tracing their development from the early days of graphical displays to their modern incarnations. This sets the stage for a focused discussion on theming options, and in particular, the increasing popularity and implementation of Dark mode in the UI design landscape. 2.1 History of User Interfaces Before GUIs, users faced a daunting blank black screen and a prompt, a design choice that did little to guide the user. In such environments, the computer's abilities remained mostly obscure to the layman. Command line interfaces (CLIs) use only text and are accessed solely by a keyboard [5]. One such example can be seen in Figure 3. with the DEC VT100 Terminal, but probably the most familiar example of a CLI to many is MS- DOS or its modern incarnation, the command prompt. Another example is Linux when it is used in shell or bash mode (i.e., the entire screen shows text only). One could say that CLI's are the living fossils of modern GUIs representing a time when interaction with computers was more text-based and less visually intuitive. Despite their seemingly archaic nature, CLI's continue to be a vital tool for developers and system administrators even today. While CLIs are still being used today, the origins of the 6 modern GUI can be traced back to the limitations and challenges posed by these text- based interfaces. Figure 3. DEC VT100 Terminal (Photo: Digital Equipment Corporation) During World War II, Vannevar Bush, a scientist and futurist who worked at the Massachusetts Institute of Technology (MIT) proposed an information administration tool called the Memex, in his now classic 1945 magazine article ‘As We May Think’ [6]. It would allow data to be stored on a microfilm and made easily accessible and linkable with hyperlinks. He envisioned the device to follow the similar associative processes as the human mind. Despite Memex being completely hypothetical, it would lay the foundation for user interfaces as we will soon see. In 1963 Ivan Sutherland, a graduate student at MIT, developed a program for his Ph.D. dissertation called Sketchpad, which allowed the direct manipulation of graphic objects on a CRT screen using a light pen. His concept included the capability to zoom in and out on the display, the provision of memory for storing objects and the ability to draw precision lines and corners on the screen [5]. Later, Douglas Engelbart was credited with the invention of the computer mouse. He was already deeply involved in human-computer interaction research at Stanford University during the early 1950s. His work was significantly influenced by Bush's Memex concept. In 1968, Engelbart introduced the world to the first rudimentary mouse at the Fall Joint 7 Computer Conference in San Francisco. Initially called the "X-Y Position Indicator for a Display System," the device was encased in a small wooden box and featured wheels. When moved on a flat surface, it controlled the cursor on the display screen. Despite its innovative design, Engelbart never earned royalties from his invention, as the patent had expired by the time the mouse became commercially available in other systems [7]. In 1970, Xerox Corporation established the Palo Alto Research Center (PARC) in California, with the ambitious goals of shaping ‘the architecture of information’ [5]. Among its contributions was the development of the first practical GUI, which was integrated into the PARC's Alto computer. Launched in 1974, the Alto was designed to be an alternative to the mainframe computers of the time. With a GUI and point-select interaction, the Star interface was the archetype of direct manipulation [7]. Parts of the icon designs can be seen in Figure 4. Despite its innovative features, MacKenzie [7] states that the Alto and its successor, the Xerox 8010 Star Information System, failed to achieve commercial success, largely due to their exorbitant pricing ($16,000 for the workstation alone). Figure 4. Icon examples that were designed for the Xerox Star desktop. During the same time frame, Steve Jobs, the co-founder of Apple Computer, was influenced by the pioneering work at PARC, which was conveniently located nearby Jobs’ residence. In exchange for shares of Apple, Xerox granted Jobs access to the PARC branch [7]. Determined to build upon PARC's innovations, Jobs and Apple engineers integrated a GUI into Apple's computer systems. Apple significantly expanded on the previous work done at PARC, introducing features like dropdown menus, interactive 8 icons, movable windows, a fixed menu bar, and a trash can for file deletion. The subsequent results of Apple’s interface design can be seen in Figure 5. Figure 5. The Apple II GS Desktop environment from 1986 (http://toastytech.com/guis/a2desk.html) The Apple Macintosh, launched in 1984, was the first commercially successful use of a GUI. It was so successful, in fact, that the GUI was subsequently adopted by most other developers of operating systems and software [5]. The Mac interface was simple and intuitive. Anyone could use it. Part of the simplicity was its one-button mouse. With one button, there was no confusion on which button to press. [7]. The success of Apple can be attributed to its competitive pricing compared to Xerox’s workstations. Also, according to MacKenzie [7], Apple always viewed their computers as personal computers, not ‘a personal computer designed for office professionals’. This user-centric focus on their computers and GUI was a recipe for success. GUIs entered the mainstream and, consequently, a much broader community of users and researchers were exposed to this new genre of interaction. Microsoft was a latecomer in GUIs [7]. Microsoft announced development of its first operating system that 9 incorporated a GUI in November 1983. Windows 2.0, released in December 1987, represented a major improvement over the primitive Windows 1.0 with its addition of icons and overlapping windows, but it was not until 1995 with the launching of Windows 95 that Microsoft was able to offer a relatively modern GUI with their new product. Moving on to the new millennia, the 2000s were marked by the rise of mobile operating systems with advanced GUIs designed for mobile use. Nokia innovated and dominated the market with their Symbian based UI, but it was not until Apple's iOS, introduced in 2007, popularized the way we interact with mobile devices. iOS offered a multi-touch interface that was both intuitive and familiarized the public with the ‘app ecosystem’ [8] of large tappable icons on users’ screens. Google's Android followed suit, providing a flexible and customizable GUI that rapidly gained market share in the mobile sphere as well. Figure 6. Apple iOS 2 mobile user interface, also known as iPhone OS 2 in 2008 10 Also, the introduction of new web technologies, such as JavaScript and Macromedia Flash (subsequently Adobe Flash), website developers were able to create more dynamic and interactive web pages. This led to the creation of more complex and sophisticated web UIs, which included animations, drop-down menus, and other interactive elements. Even online browser games were created using these technologies. As more people began to use the web for online shopping, social networking, and other activities, the need for better web UIs grew tremendously [9]. Moving in to the 2010s, the lines between desktop, mobile and web UIs began to blur. Microsoft's Windows 8, released in 2012, attempted to merge the mobile and desktop views with its ‘Metro’ interface, optimized for both touch and traditional mouse-and- keyboard input [10]. While the change was met with mixed reviews, it signified a trend towards unified interfaces across different device types as seen in Figure 7. Figure 7. Microsoft’s Metro design language’s evolution as seen in Windows 10, released on July 29, 2015. The rise of cloud computing and web applications led to the development of browser- based interfaces, blurring the lines between local and web-based software. This trend has been driven by SaaS (Software as a Service) platforms, which provide access to software applications over the internet rather than requiring local installation. Google's Chrome OS, launched in 2011, was a notable example of this trend, offering a lightweight operating system that relied heavily on web applications and cloud storage [11]. 11 2.2 Modern User Interfaces and Web Content As we proceed into the current landscape of user interfaces and web content, the lines between native and web applications have blurred, and the user experience is increasingly shaped by a blend of technologies, platforms, and devices. Historically, web services were available only through a desktop web browser. Nowadays, methods of access move beyond the desktop computer towards ubiquitous access through portable devices [12]. User interface designers, on the other hand, aim to design usable interfaces to cater for the varying requirements of these devices. One good example of the current state of web UI design is the focus on minimalism and user-centred design [9]. Design systems like Google’s Material UI (Figure 8.), Apple’s Human Interface Guidelines, and IBM’s Carbon Design System have become tools in achieving this focus. These frameworks provide a unified set of guidelines, components, and best practices that help in creating consistent and intuitive user interfaces across platforms [13]. According to Nielsen Norman Group [13], these systems help designers and developers to ensure a consistent user experience, whether the user is on a mobile device, desktop, or even using a web application. Additionally, design systems contribute to the scalability and maintainability of a product, as it alleviates strain on design resources and creates a unified language within and between cross functional teams. Figure 8. Material UI – Google provides documentation and components that developers can utilize. 12 In addition to the design systems, Web API (Application Programming Interfaces) integration should be considered as well. These APIs enable seamless integration between different services and platforms, allowing for more feature-rich and dynamic UIs. Whether it is embedding a Google Map into a web page or pulling in real-time weather data, APIs have become the building blocks of the modern web by providing extensibility and reusability [14]. You can see the basic architecture and functionality of an API in Figure 9. Building on this, APIs also make it easier for smaller developers or teams to make apps that integrate with larger platforms. This helps different services work well together, giving users a better experience overall. Using APIs can also speed up the development process, saving both time and money as developers can integrate ready-made components to their applications without starting from zero. Figure 9. Basic architecture diagram of a web API, and how communication is established with endpoints. Another relatively new development are PWAs (Progressive Web Applications). Although these web applications do not necessarily give new design standards to mobile applications, according to Tandel & Jamadar [15], PWAs continue to gain traction as they offer the best of both native and web applications. With capabilities like offline access, push notifications, and fast load times, PWAs provide a native app-like experience without requiring users to download anything from an app store. The predecessor of PWAs could be seen as early as 2007. At the launch of the iPhone in 2007, Apple announced that web applications (developed in HTML5 using AJAX architecture) would be the conventional format for iOS apps. No SDK (software development kit) was initially required, and the apps would integrate via the Safari 13 browser engine. This was later redacted, and Apple switched to the App Store design and the subsequent bundling of apps [16]. Despite the varying degrees of support from different vendors and the popularity of app stores, PWAs have seen a significant increase in adoption since 2015, both by businesses and users, due to their cross-platform nature, offline capabilities, and the enhanced user experience they offer [17]. Notable PWAs include Spotify, Uber, Google Maps, Facebook and Airbnb (see Figure 10. for example), all of which provide a native app and the web app version which can be added to the users’ home screen on their mobile device. Figure 10. Airbnb, a housing booking broker, and a marketplace website as seen in 2023, exemplifying modern web design. The same exact layout and design is in the web application and the downloadable application. In addition to PWAs, a large modern trend has been the user customizability and personalization of UIs. Custom wallpapers and screensavers have been a long-standing staple of computers and displays, but during recent years, we have seen a greater focus on personalization to maintain and solidify the relationship between users and digital products. Regardless of application type, researching new ways to provide personalised system feedback will be important going forward [18]. 14 To achieve this, new methods of data collection, such as big data analytics, are likely to influence the everyday interactions between users and systems in the near future. For this advancement, UX specialists and software engineers will need to widen their scope on the types of contextual data that can be collected with user consent. By using big data with new forms of user interfaces, application designers could establish deeper and more beneficial relationships with end users. Additionally, research could explore the role of Internet of Things (IoT) technologies in conjunction with big data. This angle could offer more personalized digital experiences for new UIs. All of this is of course all speculative, but interesting to think about. All these factors - design systems, Web APIs, Progressive Web Apps (PWAs), and customizability illustrate how modern UIs are formed and what they encase nowadays. GUIs have come a long way since the beginning of the first CLIs and windowing interfaces. Now, to set the stage for the next chapter, we will dive deeper into the concept of customizability and personalization by examining UI theming and styling standards. 15 3. Theming and Styling As we previously went over, the evolution of UI design has incorporated several developmental factors, one of which was the rising trend of UI customizability. To deliver personalized and effortless digital experiences, developers and designers have included options for users to customize their screens and content. The concept of theming and styling fits into this view, as it serves as a tool for both aesthetic appeal and improved user interaction. In this chapter, we will explore the role of theming in modern UIs and later in subsequent chapters the trend of Dark mode theming. This emphasis on user customization is not just a design trend but is backed by empirical data. A study conducted by Hui & See [19] found that the ability of the user to customize their own UI is linked to the user's sense of control over the UI. Since the sense of control over the UI is illustrated to directly impact perceived user efficiency levels, it is highly likely that customizability is proportional to the user's PEOU (Perceived Ease of Use) of the UI. Thus, by developing software that allows both developers and users to collaborate and cooperate in the creation of user-preferred UI design, we can enhance user satisfaction. Some research also points to the psychology of cognitive bias. This can be attributed to the "IKEA effect" – a cognitive bias in which consumers place higher value on things they helped to build or create [20]. This psychological principle can be extended to UI design and theming, reinforcing the importance of user customization. According to UX research, giving users agency, will create stronger bond between the user and the product. The effort that users will put into completing the product to a complete state will transform into love for that product. The subjective value will be higher in comparison to a product that has not cost any effort for the user [21]. Expanding on this psychological insight, the idea of personalization extends to the content displayed within the UI. Dynamic themes can adjust the layout, highlight particular services, or even modify textual content based on user preferences and behaviour. This level of customization not only makes the experience more engaging but also highly satisfying, as users feel their unique needs and tastes are being catered to. 16 3.1 Cascading Style Sheets (CSS) Theming and styling are not just about changing the colour scheme or adding a catchy background or a wallpaper. Theming involves tailoring visual elements and the interactive components on a technical level. This is achieved through techniques such as Cascading Style Sheets (CSS), a long-standing technology used for the layout, colouring, and fonts of web pages and applications all over. Ryan Lanciaux covers this in-depth in his book Modern Front-end Architecture [22]. CSS serves as the backbone for creating presentation styling for web content. By using a range of CSS properties and values, designers can create highly customizable themes that can be easily altered or switched out. This flexibility is especially invaluable, as it enables quick adaptations to user preferences or emerging design trends. As prefaced by Lanciaux [22], any discussion around styling web applications should start with CSS. CSS is the browser-supported way to style web applications, and it is specifically designed to be the standard language for describing the look and formatting of a document written in HTML (HyperText Markup Language). In HTML, elements are used to describe the web page, and these elements are represented by tags that can be nested inside one another. Using CSS, developers apply rules to the HTML elements and define the styles that should be applied by referring to them through selectors. A rule consists of a selector followed by a block of CSS properties contained inside curly braces. The properties consist of a property and value separated by a colon and are delimited with semicolons. A value may be a single value or a collection of multiple values, depending on the property. Every element in the document that is matched by the selector has the properties in the CSS rule applied to it [23]. An example of a CSS rule is shown in Figure 11. Figure 11. Basic syntax of a CSS rule - targeting the header-selector with properties that have certain values. 17 There are also several ways to use CSS in an HTML document: Inline styling, style blocks and external style sheets. These all have an end result: a style sheet that is applied to the HTML document. Every HTML element supports the style attribute. Inline styles are specified as CSS properties in the value of the style attribute. An inline style does not contain selectors or curly braces; it is simply a collection of CSS properties. An example of an inline style is shown in Listing 1. Listing 1. An element with inline styles: 1. 2.
3.This text is red
7. 8. In this part, we use the HTMLparagraph element and add a style attribute to it. The attribute ‘color: red;’ sets the text colour of the paragraph to red. If there are conflicts in the rules that apply to an element, its inline style always takes precedence. For example, if there was a CSS rule somewhere that made all
elements have a blue styling, this element’s inline style would override that and give it a red look. CSS rules can also be specified inside a style sheet within the HTML document itself. This is done by adding CSS rules inside of a style element. Listing 2. shows an example HTML document containing the 10. 11.
12.This text is blue.
13. 14.