Many developers use the terms "library" and "framework" interchangeably. But there is a difference and being aware of it can help you make better decisions when using third-party code.

What is a library?

According to, a library is "a collection of manuscripts, publications and other materials for reading, viewing, listening, study or reference". In programming, a library is a collection of code.

What is a framework?

According to, a framework is "a skeletal structure designed to support or enclose something". In programming, a framework is a structure that is designed to support a specific use case.

How did these terms get mixed up?

When you look at the definitions, it is clear that terms refer to two different things. But it is easy to assume that a framework refers to a large library. Or that a framework is anything that changes the way you write code.

But the real difference between a library and a framework is about who is in control.

Who is in control?

With a library, the code is provided as is and it is up to you to use it however you see fit. The only thing that a library forces on you is the interface through which you interact with it. It is up to you to use the library to achieve the result that you need.

With a framework, a predefined structure is provided to you and you then code within that structure. The framework achieves a result on its own and you can only override and customize its behavior to achieve the specific result you need.

Why does this matter?

While you could get started with libraries quite easily, they have limited functionality and you will probably need to adopt other libraries to fill in the gaps. Now the responsibility is on you to ensure that this combination of libraries work well together. Since libraries don't enforce a convention, you are also responsible for creating a structure for your code.

Frameworks tend to have more conventions so they can be harder to learn. But you can move faster once you are familiar with those conventions since a framework does more of the work for you. However, changing the conventions and the functionality of a framework is difficult and you can be forced to adopt practices that you don't like or are not useful for your use case.

Which is better?

There is no fixed answer to whether a framework or a library is better. Depending on your preferences and circumstances, either one could be a better fit. But it is important to consider the limitations of each before you adopt it.

In the case of a framework, this is whether the functionality it provides is worth the extra effort of understanding and adopting its conventions and whether its functionality and conventions are not too limiting.

In the case of a library, this is whether you can maintain the combination of libraries that achieves your use case and whether you are capable of adopting good conventions for using them.

Prabashwara Seneviratne

Written by

Prabashwara Seneviratne

Author. Lead frontend developer.