Configurar tema oscuro en Angular Material

Guía para implementar y cambiar el tema oscuro en Angular Material con SCSS y TypeScript, usando color-scheme y preferencias del sistema o selección manual, con ejemplos y foco en Q2BSTUDIO.

18 ago 2025 • 3 min read • Q2BSTUDIO Team

Inteligencia-Artificial-

Hace tiempo que el tema oscuro se ha convertido en un estándar para muchas aplicaciones aunque no siempre es imprescindible. En este artículo explicaré cómo aplicar un tema oscuro con Angular Material y cómo permitir que el usuario lo cambie. También incluyo ejemplos de SCSS y TypeScript para facilitar la implementación.

Primero configure el tema general de Material. Un ejemplo de SCSS para el tema base sería:

html { @include mat.theme(( color: mat.$azure-palette, typography: Roboto, )); }

Con esto estará usando el tema claro por defecto. Para soportar modo oscuro aprovechamos la propiedad CSS color-scheme y la capacidad interna de Angular Material para alternar light y dark:

html { color-scheme: light dark; @include mat.theme(( color: mat.$azure-palette, typography: Roboto, )); }

Al establecer color-scheme: light dark el modo por defecto se adapta a la preferencia del sistema del usuario. Además puede sobrescribir propiedades específicas cuando el modo oscuro está activo, por ejemplo el fondo:

html { color-scheme: light dark; @include mat.theme(( color: mat.$azure-palette, typography: Roboto, )); @media (prefers-color-scheme: dark) { @include mat.theme(( color: mat.$azure-palette ), $overrides: ( background: darkblue ) ); } }

Si desea que el usuario cambie el tema manualmente cree un control toggle o select con las opciones system, light y dark. Un ejemplo sencillo en TypeScript con signal y Renderer2 para aplicar el estilo al body:

public readonly theme = signal(system); private readonly _renderer = inject(Renderer2); constructor() { effect(() => this._setTheme(this.theme())); } private _setTheme(theme: ThemeMode) { this._renderer.setProperty(document.body.style, color-scheme, theme === system ? light dark : theme); }

La idea es almacenar la preferencia del usuario en local storage o en su perfil y restaurarla en cada carga. También puede ofrecer un modo system que respete la preferencia del sistema y un modo manual para forzar claro u oscuro.

Como bonus puede mejorar la transición visual entre temas usando la experimental API startViewTransition cuando el navegador la soporte. Un ejemplo de uso en un componente:

constructor(@Inject(DOCUMENT) private readonly _document: Document) { effect(() => { const theme = this.theme(); if (!this._document.startViewTransition) { this._setTheme(theme); return; } this._document.startViewTransition(() => { this._setTheme(theme); }); }); }

Y un ejemplo de animación CSS para la nueva vista:

::view-transition-old(root) { animation-delay: 500ms; } ::view-transition-new(root) { animation: circle-in 500ms; } @keyframes circle-in { from { clip-path: circle(0% at 50% 0%); } to { clip-path: circle(120% at 50% 0%); } }

Con estos cambios tendrá un control completo sobre el tema oscuro en Angular Material y podrá ofrecer una experiencia pulida tanto para usuarios que siguen la preferencia del sistema como para los que eligen manualmente.

Sobre nosotros: en Q2BSTUDIO somos una empresa de desarrollo de software y aplicaciones a medida especializada en soluciones tecnológicas avanzadas. Ofrecemos servicios de software a medida, aplicaciones a medida, inteligencia artificial, ia para empresas, agentes IA y desarrollo de experiencias con Power BI. También ayudamos a las organizaciones con ciberseguridad, servicios cloud aws y azure y servicios inteligencia de negocio para tomar decisiones basadas en datos.

Si necesita integrar un tema oscuro como parte de una aplicación a medida o quiere que su producto incluya capacidades de inteligencia artificial o ciberseguridad contacte con Q2BSTUDIO. Podemos diseñar software a medida, integrar agentes IA, implementar soluciones de inteligencia artificial y servicios cloud aws y azure, y crear paneles con power bi para exponer indicadores clave.

Palabras clave para mejorar el posicionamiento: aplicaciones a medida, software a medida, inteligencia artificial, ciberseguridad, servicios cloud aws y azure, servicios inteligencia de negocio, ia para empresas, agentes IA, power bi.

Si quiere que implementemos esta funcionalidad en su proyecto o desea una consultoría sobre seguridad, cloud o inteligencia artificial, en Q2BSTUDIO estamos preparados para ayudarle con soluciones personalizadas y escalables.

A BREAK?

Play for a moment before you go

OUR SERVICES

How we can help you

Artificial intelligence

AI agents, chatbots, and intelligent assistants that automate tasks and serve your customers 24/7 to improve the efficiency of your business.

More info

Software Development

Web, mobile, and desktop applications, intranets, e-commerce, SaaS, and management platforms designed for your company's specific needs.

More info

Cloud services

Migration, infrastructure, managed hosting, high availability, and security on Microsoft Azure and Amazon Web Services to help your business scale without limits.

More info

Cybersecurity and pentesting

Security audits, penetration testing and protection of applications, data and infrastructure on-premise and cloud, with ethical hacking and regulatory compliance.

More info

Business Intelligence

Dashboards and data analysis with Power BI: we integrate your sources, design dashboards and KPIs and turn your data into decisions.

More info

Process automation

We automate repetitive tasks and connect your applications with n8n, Power Automate, Make, and RPA, eliminating manual work and increasing productivity.

More info

Training for Companies

We train your teams in technology with criteria: web development, databases, Git, best practices and security, automation with n8n, artificial intelligence for companies and creation of AI solutions with Azure AI Foundry.

More info

Code Auditing

We audit the code that you, your team or an AI create: we tell you what is good and what to improve, we secure it and make it ready for production, web or app.

More info

AI Image Generation

We create for you the images that your business needs with artificial intelligence: product, networks, advertising, illustration and avatars. You tell us what you want and we deliver it ready to use.

More info

AI Video Generation

We create videos with artificial intelligence for you: promotional, networking, virtual presenters, dubbing and animations. You tell us the idea and we will deliver it assembled and ready to publish.

More info

AI Conversational Avatars

We create conversational avatars with AI – digital humans with a face and voice – that serve your customers and teams with the knowledge of your company, on your website, interactive monitors, WhatsApp or Teams.

More info

Online Marketing and AI

Google Ads, Meta Ads, LinkedIn Ads and AI Engine Positioning (GEO/AEO): we attract customers and make your brand appear where they search for you, also on ChatGPT, Gemini and Perplexity.

More info

Do you have a project in mind?

Tell us your vision and we'll turn it into a software solution. Whatever the scope, we make your idea real.

Live Chat